builder.Services
.AddOpenTelemetry()
.UseAzureMonitor()
.ConfigureResource(r => r.AddService("XYZ"))
.WithTracing(b => b
.AddSource("X")
.AddAzureMonitorTraceExporter())
.WithMetrics(b => b
.AddMeter("X")
.AddAzureMonitorMetricExporter());
I am trying to integrate my app with Azure Monitor by using UseAzureMonitor extension and my custom Tracing and Metrics.
Separately they work as excepted, but when I use them both, all logs, counters etc duplicates.
When I comment UseAzureMonitor
out I lose logs and http traces.
When I comment out WithTracing
and ‘WithMetrics’ I lose all my custom telemetry data and yet when I use them both, all data (logs,counters etc.) is duplicated.
Is there a way to use them both? How to configure that?
2
Answers
Here is my fixed configuration, that meets my needs
I tried configuring both
UseAzureMonitor
and custom Open Telemetry tracing & metrics, its giving duplicate logs.This happens because both Azure Monitor’s default settings and your custom setup are recording the same data, which causes duplicate logs in your telemetry.
To prevent duplicate telemetry logs, it’s better to skip
UseAzureMonitor
and set up OpenTelemetry manually. This ensures your custom configuration remains clear and avoids any overlap with default telemetry.If you want to use both
UseAzureMonitor
and custom OpenTelemetry tracing and metrics without duplicate logs, you can apply filters to prevent multiple logs.Refer this doc for better understanding about how to add filters.
This my DuplicateTraceFilterProcessor.cs file
Here I got the logs without any duplicate traces.