Skip to content

Commit 7252b82

Browse files
author
Timothy Mothra
authored
[AzureMonitorExporter] emit warning if LiveMetrics not supported (Azure#49830)
* minor change, emit warning if LiveMetrics not supported * Revert "minor change, emit warning if LiveMetrics not supported" This reverts commit 91313c9. * pr feedback * cleanup * cleanup * rephrase warning message
1 parent d817a2d commit 7252b82

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/AzureMonitorExporterExtensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Diagnostics;
88
using Azure.Core;
99
using Azure.Monitor.OpenTelemetry.Exporter.Internals;
10+
using Azure.Monitor.OpenTelemetry.Exporter.Internals.Diagnostics;
1011
using Microsoft.Extensions.DependencyInjection;
1112
using Microsoft.Extensions.Options;
1213
using OpenTelemetry;
@@ -73,6 +74,11 @@ public static TracerProviderBuilder AddAzureMonitorTraceExporter(
7374
configure(exporterOptions);
7475
}
7576

77+
if (exporterOptions.EnableLiveMetrics == true)
78+
{
79+
AzureMonitorExporterEventSource.Log.LiveMetricsNotSupported(methodName: nameof(AddAzureMonitorTraceExporter));
80+
}
81+
7682
builder.SetSampler(new ApplicationInsightsSampler(exporterOptions.SamplingRatio));
7783

7884
if (credential != null)
@@ -138,6 +144,11 @@ public static MeterProviderBuilder AddAzureMonitorMetricExporter(
138144
configure(exporterOptions);
139145
}
140146

147+
if (exporterOptions.EnableLiveMetrics == true)
148+
{
149+
AzureMonitorExporterEventSource.Log.LiveMetricsNotSupported(methodName: nameof(AddAzureMonitorMetricExporter));
150+
}
151+
141152
if (credential != null)
142153
{
143154
// Credential can be set by either AzureMonitorExporterOptions or Extension Method Parameter.
@@ -176,6 +187,11 @@ public static OpenTelemetryLoggerOptions AddAzureMonitorLogExporter(
176187
var options = new AzureMonitorExporterOptions();
177188
configure?.Invoke(options);
178189

190+
if (options.EnableLiveMetrics == true)
191+
{
192+
AzureMonitorExporterEventSource.Log.LiveMetricsNotSupported(methodName: nameof(AddAzureMonitorLogExporter));
193+
}
194+
179195
if (credential != null)
180196
{
181197
// Credential can be set by either AzureMonitorExporterOptions or Extension Method Parameter.
@@ -236,6 +252,11 @@ public static LoggerProviderBuilder AddAzureMonitorLogExporter(
236252
exporterOptions = sp.GetRequiredService<IOptionsMonitor<AzureMonitorExporterOptions>>().Get(finalOptionsName);
237253
}
238254

255+
if (exporterOptions.EnableLiveMetrics == true)
256+
{
257+
AzureMonitorExporterEventSource.Log.LiveMetricsNotSupported(methodName: nameof(AddAzureMonitorLogExporter));
258+
}
259+
239260
if (credential != null)
240261
{
241262
// Credential can be set by either AzureMonitorExporterOptions or Extension Method Parameter.

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/AzureMonitorExporterOptions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ public enum ServiceVersion
9191
/// Note: Enabling Live Metrics incurs no additional billing or costs. However, it does introduce
9292
/// a performance overhead due to extra data collection, processing, and networking calls. This overhead
9393
/// is only significant when the LiveMetrics portal is actively used in the UI. Once the portal is closed,
94+
/// </summary>
9495
/// LiveMetrics reverts to a 'silent' mode with minimal to no overhead.
96+
/// <remarks>
9597
/// This setting is applicable only when `UseAzureMonitorExporter` API is used.
9698
/// <see href="https://learn.microsoft.com/azure/azure-monitor/app/live-stream"/>.
97-
/// </summary>
99+
/// </remarks>
98100
public bool EnableLiveMetrics { get; set; } = true;
99101

100102
/// <summary>

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/Diagnostics/AzureMonitorExporterEventSource.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,5 +455,8 @@ public void ConfigureFailed(System.Exception ex)
455455

456456
[Event(44, Message = "Failed to configure AzureMonitorExporterOptions using the connection string from environment variables due to an exception: {0}", Level = EventLevel.Error)]
457457
public void ConfigureFailed(string exceptionMessage) => WriteEvent(44, exceptionMessage);
458+
459+
[Event(45, Message = "The {0} method received an AzureMonitorExporterOptions with EnableLiveMetrics set to true, which isn't supported. Note that LiveMetrics is only available via the UseAzureMonitorExporter API.", Level = EventLevel.Warning)]
460+
public void LiveMetricsNotSupported(string methodName) => WriteEvent(45, methodName);
458461
}
459462
}

0 commit comments

Comments
 (0)