Skip to content
No description, website, or topics provided.
C#
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
AppInsights.Enricher.sln
LICENSE
README.md

README.md

AppInsights.Enricher

Could be downloaded from NuGet:

  • Install-Package AppInsights.Enricher
  • dotnet add package AppInsights.Enricher
  • paket add AppInsights.Enricher

How to use it:

  • implement own ITelemetryEnricher You say here when you want to store Request/Response:
public class CustomTelemetryEnricher : ITelemetryEnricher
{
    public ITelemetry Enrich(ITelemetry tele) => tele;
    public bool AttachRequest(HttpContext context) => true;
    public bool AttachResponse(HttpContext context) => context?.Request?.Path.Value?.Contains("mail") == true;
}
  • implement own IProcessorApplier You say here when you want to log data to AppInsights
public class CustomProcessorApplier: IProcessorApplier
{
    public bool Apply(ITelemetry tele)
    {
        if (tele is RequestTelemetry request)
        {
            var isItBadRequestOrConnection = request.ResponseCode == "404";
            if (isItBadRequestOrConnection)
                return false;
        }

        if (!(tele is DependencyTelemetry dependency)) return true;

        return true;
    }
}
  • Register it in container
services.AddApplicationInsightsKubernetesEnricher();
services.AddSingleton<IProcessorApplier, CustomProcessorApplier>();
services.AddSingleton<ITelemetryEnricher, CustomTelemetryEnricher>();
services.AddSingleton<IRequestDataAccessor>(new RequestDataAccessor(1_000, 1_000, 100_000));
return services.AddTelemetry<TelemetryProcessor>(configuration);

And that's all!

You can’t perform that action at this time.