Skip to content

Commit

Permalink
[AzureMonitorDistro] Add LiveMetricsActivityProcessor only when live …
Browse files Browse the repository at this point in the history
…metrics is enabled (#43524)

* Add LiveMetricsActivityProcessor only when live metrics is enabled

* Rename azureMonitorOptions to options.
  • Loading branch information
rajkumar-rangaraj authored Apr 19, 2024
1 parent a6c3e59 commit 70f5c48
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,18 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
return true;
})
.AddProcessor<ProfilingSessionTraceProcessor>()
.AddProcessor(sp =>
{
var manager = sp.GetRequiredService<Manager>();
return new LiveMetricsActivityProcessor(manager);
})
.AddAzureMonitorTraceExporter());

builder.Services.ConfigureOpenTelemetryTracerProvider((sp, builder) =>
{
var azureMonitorOptions = sp.GetRequiredService<IOptionsMonitor<AzureMonitorOptions>>().Get(Options.DefaultName);
if (azureMonitorOptions.EnableLiveMetrics)
{
var manager = sp.GetRequiredService<Manager>();
builder.AddProcessor(new LiveMetricsActivityProcessor(manager));
}
});

builder.WithMetrics(b => b
.AddHttpClientAndServerMetrics()
.AddAzureMonitorMetricExporter());
Expand All @@ -141,11 +146,6 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
logging.AddOpenTelemetry(builderOptions =>
{
builderOptions.IncludeFormattedMessage = true;
builderOptions.AddProcessor(sp =>
{
var manager = sp.GetRequiredService<Manager>();
return new LiveMetricsLogProcessor(manager);
});
});
});

Expand Down Expand Up @@ -178,6 +178,15 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
{
loggingOptions.AddAzureMonitorLogExporter(o => azureMonitorOptions.SetValueToExporterOptions(o));
}

if (azureMonitorOptions.EnableLiveMetrics)
{
loggingOptions.AddProcessor(sp =>
{
var manager = sp.GetRequiredService<Manager>();
return new LiveMetricsLogProcessor(manager);
});
}
});

// Register a configuration action so that when
Expand Down

0 comments on commit 70f5c48

Please sign in to comment.