Skip to content

Commit

Permalink
docs: improve telemetry filter feature docs (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnmoreels committed Jan 5, 2023
1 parent 50fae05 commit 56cbbd9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/preview/03-Features/telemetry-filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ PM > Install-Package Arcus.Observability.Telemetry.Serilog.Filters

## Telemetry Type Filter

In certain scenarios, the cost of having too much telemetry or having a certain type of telemetry in your logging can be too high to be useful. We could, for example, filter out in container logs the Request, Metrics and Dependencies, and discard all the other types to make the logging output more readable and cost-effective.

This [Serilog filter](https://github.com/serilog/serilog/wiki/Enrichment) allows you to filter out different a specific type of telemetry.

```csharp
Expand All @@ -24,7 +26,7 @@ using Serilog.Core;
using Serilog.Configuration;

ILogger logger = new LoggerConfiguration()
.WriteTo.AzureApplicationInsights("<key>")
.WriteTo.AzureApplicationInsightsWithConnectionString("<connection-string>")
.Filter.With(TelemetryTypeFilter.On(TelemetryType.Events))
.CreateLogger();
```
Expand All @@ -33,18 +35,18 @@ The filter can also be used to reduce telemetry for multiple types by chaining t

```csharp
ILogger logger = new LoggerConfiguration()
.WriteTo.AzureApplicationInsights("<key>")
.WriteTo.AzureApplicationInsightsWithConnectionString("<connection-string>")
.Filter.With(TelemetryTypeFilter.On(TelemetryType.Events))
.Filter.With(TelemetryTypeFilter.On(TelemetryType.Dependency))
.CreateLogger();
```

Alternatively, you can explicitly specify if it should track telemetry or not based on the application configuration has to be tracked or not :
Alternatively, you can explicitly specify if it should track telemetry or not based on the application configuration has to be tracked or not:

```csharp
var trackDependencies = configuration["telemetry:dependencies:isEnabled"];
ILogger logger = new LoggerConfiguration()
.WriteTo.AzureApplicationInsights("<key>")
.WriteTo.AzureApplicationInsightsWithConnectionString("<connection-string>")
.Filter.With(TelemetryTypeFilter.On(TelemetryType.Dependency, isTrackingEnabled: bool.Parse(trackDependencies)))
.CreateLogger();
```
Expand Down

0 comments on commit 56cbbd9

Please sign in to comment.