Is there an existing issue for this?
Describe the bug
Microsoft.AspNetCore.Components telemetry appears to be disabled in .NET 11 preview unless the System.Diagnostics.Metrics.Meter.IsSupported AppContext switch is explicitly enabled.
This changed with #65901, which added guards for both:
ComponentsMetrics
ComponentsActivitySource
using:
AppContext.TryGetSwitch("System.Diagnostics.Metrics.Meter.IsSupported", out var isSupported) ? isSupported : false;
This is problematic for OpenTelemetry instrumentation. OpenTelemetry.Instrumentation.AspNetCore listens to Microsoft.AspNetCore.Components for both metrics and traces:
However, in .NET 11 preview, those listeners are no longer enough. The application must also enable the AppContext switch before ASP.NET Core Components telemetry is initialized.
This is surprising for two reasons:
- Component tracing is gated by a metrics switch.
- The default differs from
System.Diagnostics.Metrics.Meter.IsSupported, which defaults to true when the switch is not configured.
The issue was found while working on .NET 11 support for https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation.
Expected Behavior
Bring back previous behavior. Switch should not be needed.
It is important, because this https://learn.microsoft.com/en-us/aspnet/core/log-mon/metrics/built-in?view=aspnetcore-11.0 does not mention any other changes than only listening on this.
Steps To Reproduce
Create a Blazor/Razor Components app targeting .NET 11 preview and configure OpenTelemetry both for .NET 10 and .NET 11:
builder.Services.AddOpenTelemetry()
.WithTracing(tracing =>
{
tracing
.AddSource("Microsoft.AspNetCore.Components")
.AddConsoleExporter();
})
.WithMetrics(metrics =>
{
metrics
.AddMeter("Microsoft.AspNetCore.Components")
.AddMeter("Microsoft.AspNetCore.Components.Lifecycle")
.AddConsoleExporter();
});
Run the app and trigger component activity, for example navigation or event handling.
Observed behavior:
- No
Microsoft.AspNetCore.Components traces are emitted.
- No
Microsoft.AspNetCore.Components metrics are emitted.
Then add the switch very early in app startup:
AppContext.SetSwitch("System.Diagnostics.Metrics.Meter.IsSupported", true);
Observed behavior after enabling the switch:
Microsoft.AspNetCore.Components telemetry is emitted.
Exceptions (if any)
No response
.NET Version
11.0.100-preview.4.26230.115
Anything else?
Switch name is strange, as it covers both metrics and traces.
Is there an existing issue for this?
Describe the bug
Microsoft.AspNetCore.Componentstelemetry appears to be disabled in .NET 11 preview unless theSystem.Diagnostics.Metrics.Meter.IsSupportedAppContext switch is explicitly enabled.This changed with #65901, which added guards for both:
ComponentsMetricsComponentsActivitySourceusing:
This is problematic for OpenTelemetry instrumentation.
OpenTelemetry.Instrumentation.AspNetCorelistens toMicrosoft.AspNetCore.Componentsfor both metrics and traces:AddMeter("Microsoft.AspNetCore.Components")https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/1c4410fc297d02d448ce98783aeb70d6c5d51289/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationMeterProviderBuilderExtensions.cs#L57AddSource("Microsoft.AspNetCore.Components")https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/1c4410fc297d02d448ce98783aeb70d6c5d51289/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationTracerProviderBuilderExtensions.cs#L150However, in .NET 11 preview, those listeners are no longer enough. The application must also enable the AppContext switch before ASP.NET Core Components telemetry is initialized.
This is surprising for two reasons:
System.Diagnostics.Metrics.Meter.IsSupported, which defaults totruewhen the switch is not configured.The issue was found while working on .NET 11 support for https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation.
Expected Behavior
Bring back previous behavior. Switch should not be needed.
It is important, because this https://learn.microsoft.com/en-us/aspnet/core/log-mon/metrics/built-in?view=aspnetcore-11.0 does not mention any other changes than only listening on this.
Steps To Reproduce
Create a Blazor/Razor Components app targeting .NET 11 preview and configure OpenTelemetry both for .NET 10 and .NET 11:
Run the app and trigger component activity, for example navigation or event handling.
Observed behavior:
Microsoft.AspNetCore.Componentstraces are emitted.Microsoft.AspNetCore.Componentsmetrics are emitted.Then add the switch very early in app startup:
Observed behavior after enabling the switch:
Microsoft.AspNetCore.Componentstelemetry is emitted.Exceptions (if any)
No response
.NET Version
11.0.100-preview.4.26230.115
Anything else?
Switch name is strange, as it covers both metrics and traces.