Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mnie/appinsights.enricher

Enrich your telemetry data!
https://github.com/mnie/appinsights.enricher

appinsights azure csharp telemetry

Last synced: 2 days ago
JSON representation

Enrich your telemetry data!

Awesome Lists containing this project

README

        

# AppInsights.Enricher [![NuGet](https://buildstats.info/nuget/AppInsights.Enricher?includePreReleases=true)](https://www.nuget.org/packages/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:

```csharp
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

```csharp
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

```csharp
services.AddApplicationInsightsKubernetesEnricher();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton(new RequestDataAccessor(1_000, 1_000, 100_000));
return services.AddTelemetry(new ApplicationInsightsServiceOptions { InstrumentationKey = "your_key" });
```

And that's all!

If you want to read more about using this lib, you could take a look [at my blog post about it](https://www.mnie.me/appinsightslogging).