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

Abierto Apto para principiantes
#70,516 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp

Línea de trabajo

Empieza en src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs, especialmente en el código citado alrededor de las líneas 486 y 595-601, para rastrear dónde Hosting establece y luego reemplaza Activity.DisplayName. Revisa las pruebas relacionadas de diagnósticos de hosting y ejecuta las pruebas específicas de este comportamiento. Se considera terminado cuando se conserva un nombre establecido por la aplicación, mientras que un nombre sin cambios que solo contiene el método sigue convirtiéndose en {method} {route}.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

area-hosting Regression
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
Lenguaje dominante
C#
Estrellas
38.5k
Forks
12.3k
Merge medio
3 d 2 h
PR fusionados (30 d)
283

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dotnet/aspnetcore

Todos los issues de dotnet/aspnetcore

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.