Skip to content

*Breaking change* ASP.NET Core Components telemetry requires System.Diagnostics.Metrics.Meter.IsSupported in .NET 11 preview #66822

Description

@Kielek

Is there an existing issue for this?

  • I have searched the existing issues

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:

  1. Component tracing is gated by a metrics switch.
  2. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor Components

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions