Skip to content

[OpenTelemetry] Hosting replaces an Activity.DisplayName that the app set, when a route matches #70516

Description

@PetarJerinic

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

.NET 11 (#64851) sets Activity.DisplayName to {method} {route} at the end of the request when a route matches. It does not check the current name (HostingApplicationDiagnostics.cs#L595-L601). This means that a name that the app sets during the request is lost.

In .NET 10, hosting does not write DisplayName at the end of the request, and the name from the app stays. The repro below prints custom-name on .NET 10 and GET /items/{id} on .NET 11.

The OpenTelemetry instrumentation had the same problem on .NET 10 and earlier (open-telemetry/opentelemetry-dotnet-contrib#1948). On .NET 11 the instrumentation leaves the rename to hosting, so it cannot keep the name.

Expected Behavior

Hosting replaces the name only when it still has the method-only name that hosting set at the start (L486). A name that the app sets stays.

If the app does not set a name, the result does not change: the span gets {method} {route}. The check is one string comparison at the end of the request.

Steps To Reproduce

Repro: https://github.com/PetarJerinic/aspnetcore-displayname-repro

using System.Diagnostics;
using Microsoft.AspNetCore.Http.Features;

using var listener = new ActivityListener
{
    ShouldListenTo = source => source.Name == "Microsoft.AspNetCore",
    Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllDataAndRecorded,
    ActivityStopped = activity => Console.WriteLine($"Stopped: DisplayName = '{activity.DisplayName}'"),
};
ActivitySource.AddActivityListener(listener);

var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseUrls("http://127.0.0.1:5099");
builder.Logging.ClearProviders();
var app = builder.Build();

app.MapGet("/items/{id}", (HttpContext context) =>
{
    // The app gives the span a more useful name.
    context.Features.Get<IHttpActivityFeature>()!.Activity.DisplayName = "custom-name";
    return "ok";
});

await app.StartAsync();
using var client = new HttpClient();
await client.GetStringAsync("http://127.0.0.1:5099/items/1");
await app.StopAsync();

dotnet run output:

  • net10.0 (10.0.13): Stopped: DisplayName = 'custom-name'
  • net11.0 (11.0.0): Stopped: DisplayName = 'GET /items/{id}'

Exceptions (if any)

No response

.NET Version

11.0.100

Anything else?

  • ASP.NET Core version: 11.0.0
  • OS: macOS

Activity

  1. added theissue type on Nov 11, 2026
  2. github-actions commented on Nov 11, 2026

    @github-actions
    Contributor

    Triage Summary

    Area: area-hosting (HostingApplicationDiagnostics in src/Hosting/Hosting)
    Type: Bug (preserved)

    Regression Info

    • Previously working version: .NET 10 (10.0.13), per the reporter
    • Failing version: .NET 11 (11.0.0), per the reporter
    • Reporter states the app-set Activity.DisplayName (custom-name) is kept on .NET 10 but replaced by GET /items/{id} on .NET 11.

    Potential Duplicates

    • None found

    Generated by Issue Triage Agent for dotnet/aspnetcore for #70516 · copilot · auto · 21.7 AIC · ⌖ 1.01 AIC · ⊞ 7.5K · ◷

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Regressionarea-hosting

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions