Tingle.AspNetCore.ApplicationInsights 4.7.0

dotnet add package Tingle.AspNetCore.ApplicationInsights --version 4.7.0
NuGet\Install-Package Tingle.AspNetCore.ApplicationInsights -Version 4.7.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tingle.AspNetCore.ApplicationInsights" Version="4.7.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tingle.AspNetCore.ApplicationInsights --version 4.7.0
#r "nuget: Tingle.AspNetCore.ApplicationInsights, 4.7.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Tingle.AspNetCore.ApplicationInsights as a Cake Addin
#addin nuget:?package=Tingle.AspNetCore.ApplicationInsights&version=4.7.0

// Install Tingle.AspNetCore.ApplicationInsights as a Cake Tool
#tool nuget:?package=Tingle.AspNetCore.ApplicationInsights&version=4.7.0

Tingle.AspNetCore.ApplicationInsights

[!CAUTION] This documentation for Tingle.AspNetCore.ApplicationInsights may not cover the most recent version of the code. Use it sparingly

See https://github.com/tinglesoftware/dotnet-extensions/issues/224

This is a customized library developed by Tingle. The ApplicationInsights package in AspNetCore offers functionality to understand how the application is performing and how it is being used. Tingle.AspNetCore.ApplicationInsights has additional functionality for Application Insights on AspNetCore mainly used in building Tingle APIs and Services.

Adding to Service Collections

The following logic is added to Program.cs file:

// Enables Application Insights telemetry collection
builder.Services.AddApplicationInsightsTelemetryExtras(builder.Configuration)

This library has a number of extensibility points, one of them being the telemetry initializer. To implement the telemetry initializer, a class is created that implements the ITelemetryInitializer interface. In this case, ExtrasTelemetryInitializer is a class implementing ITelemetryInitializer interface. The ExtrasTelemetryInitializer extends ApplicationInsights telemetry collection by supplying additional information about the application which includes the AppPackageId, AppVersionName, AppVersionCode, AppClient, AppIpAddress and AppKind.

In the ITelemetryInitializer interface's Initialize method, a HttpContext object is created. Whenever a new HTTP request or response is made, a HttpContext object is created which wraps all HTTP related information in one place. The HttpContext object is accessed through the IHttpContextAccessor and its default implementation HttpAccessor. It is necessary to use the IHttpContextAccessor so as to access the HttpContext object within a service.

The initializers are used to mark every collected telemetry item with the current web request identity so that traces and exceptions can be correlated to corresponding requests.

The library is used to track error details in application insights when the response is BadRequestObjectResult with the value of type ProblemDetails.

From the request header, the application's package ID, version name, version code, client, IP address and kind properties are extracted so that the traces and exceptions can be correlated/matched to the corresponding requests.

Configuration

The instrumentation key is specified in configuration. The following code sample shows how to specify an instrumentation key in appsettings.json.

{
  "ApplicationInsights:InstrumentationKey":"#{ApplicationInsightsInstrumentationKey}#"
}

Sample Usage

[TrackProblems]
[ApiVersion("1")]
[Route("v{version:apiVersion}/[controller]")]
public class DummyController : ControllerBase
{
  [HttpPost]
  [ProducesResponseType(typeof(RequestEntry), 200)]
  [ProducesResponseType(typeof(ErrorModel), 400)]
  public async Task<IActionResult> SendAsync([FromBody] SendRequestModel model)
  {
      ...
      // In case of a bad request
      return Problem(title: "error_title", description: "more detailed description", statusCode: 400);
      ...
    }
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.7.0 528 3/25/2024