CcAcca.ApplicationInsights.ProblemDetails 2.0.0

dotnet add package CcAcca.ApplicationInsights.ProblemDetails --version 2.0.0                
NuGet\Install-Package CcAcca.ApplicationInsights.ProblemDetails -Version 2.0.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="CcAcca.ApplicationInsights.ProblemDetails" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CcAcca.ApplicationInsights.ProblemDetails --version 2.0.0                
#r "nuget: CcAcca.ApplicationInsights.ProblemDetails, 2.0.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 CcAcca.ApplicationInsights.ProblemDetails as a Cake Addin
#addin nuget:?package=CcAcca.ApplicationInsights.ProblemDetails&version=2.0.0

// Install CcAcca.ApplicationInsights.ProblemDetails as a Cake Tool
#tool nuget:?package=CcAcca.ApplicationInsights.ProblemDetails&version=2.0.0                

ApplicationInsights.ProblemDetails Build Status

Overview

MS Application Insights integration for the Hellang.Middleware.ProblemDetails package.

Enriches request telemetry with custom dimensions extracted from a ProblemDetail response:

Screenshot of enriched telemetry captured in Application Insights

Usage

Prerequisites

Ensure your ASP.Net Core application has been configured with:

Steps

  1. Install package

    dotnet add package CcAcca.ApplicationInsights.ProblemDetails
    
  2. Register the library with .Net Core dependency injection system. In Statup.ConfigureServices method add:

    services.AddProblemDetailTelemetryInitializer()
    

Configuration / customization

  • Configure which ProblemDetail responses are sent to application insights:

    services.AddProblemDetailTelemetryInitializer(o => {
       o.ShouldSend = (ctx, problem) => problem.Status >= StatusCodes.Status500InternalServerError;
    })
    
  • Configure which properties of an ProblemDetail should be sent to application insights:

    services.AddProblemDetailTelemetryInitializer(o => {
      o.IncludeErrorsValue = (ctx, problem) => !SensitiveUrl(ctx);
      o.IncludeExtensionsValue = (ctx, problem) => !SensitiveUrl(ctx);
      o.IncludeRawJson = (ctx, problem) => !SensitiveUrl(ctx);
    });
    
  • Configure the values of the dimensions sent to application insights:

    services.AddProblemDetailTelemetryInitializer(o => {
      o.MapDimensions = (ctx, problem, dimensions) => {
        var sensitiveFields = new[] {"SSN", "SocialSecurityNumber", "AccountNumber"};
        var isSensitive = dimensions.Any(d => sensitiveFields.Any(f => d.Key.Contains(f)));
        var sanitized = isSensitive
          ? dimensions
            .Where(d =>
              !sensitiveFields.Concat(new[] {DefaultDimensionCollector.RawDimensionKey})
                .Any(f => d.Key.Contains(f)))
          : dimensions;
        return new Dictionary<string, string>(sanitized);
      };
    });
    
  • Configure when a ProblemDetail should be considered a success/failure

    // only status codes >= 500 treat as a failure
    services.AddProblemDetailTelemetryInitializer(options => {
        options.IsFailure = ProblemDetailsTelemetryOptions.ServerErrorIsFailure;
    });
    
  • Override the default serializer: see ProblemDetailsTelemetryOptions.SerializeValue

  • Override the default dimension collector for low level control: see DefaultDimensionCollector

Develop

To build and run tests you can use:

  • the dotnet cli tool
  • any IDE/editor that understands MSBuild eg Visual Studio or Visual Studio Code
  • Develop on a feature branch created from master:
    • create a branch from master.
    • perform all the code changes into the newly created branch.
    • merge master into your branch, then run tests locally (eg dotnet test src/CcAcca.ApplicationInsights.ProblemDetails.Tests)
    • on the new branch, bump the version number in CcAcca.ApplicationInsights.ProblemDetails.csproj; follow semver
    • update CHANGELOG.md
    • raise the PR (pull request) for code review & merge request to master branch.
    • PR will auto trigger a limited CI build (compile and test only)
    • approval of the PR will merge your branch code changes into the master

CI server

Github actions is used to run the dotnet cli tool to perform the build and test. See the yaml build definition for details.

Notes:

  • The CI build is configured to run on every commit to any branch
  • PR completion to master will also publish the nuget package for CcAcca.ApplicationInsights.ProblemDetails to Nuget gallery
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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 was computed.  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
2.0.0 35,365 11/18/2023
2.0.0-beta.2 102 9/17/2023
2.0.0-beta.1 56 9/17/2023
1.1.1 103,645 12/2/2021
1.1.0 30,920 6/2/2021
1.0.2 912 6/1/2021
1.0.1 914 4/20/2021
1.0.0 1,019 3/29/2021