From af57940e4283dad4d63e7b4894d508bc20c47c58 Mon Sep 17 00:00:00 2001 From: martincostello Date: Mon, 6 Apr 2026 17:00:25 +0100 Subject: [PATCH 1/6] [AspNetCore] Add schema URL to traces Add schema URL to the `ActivitySource`. Contributes to #4064. --- ...entationTracerProviderBuilderExtensions.cs | 2 +- .../CHANGELOG.md | 3 ++ .../Implementation/HttpInListener.cs | 28 ++++++++++++++----- ...elemetry.Instrumentation.AspNetCore.csproj | 11 ++++---- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationTracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationTracerProviderBuilderExtensions.cs index d18e17357a..d3d7b36aa2 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationTracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationTracerProviderBuilderExtensions.cs @@ -122,7 +122,7 @@ private static void AddAspNetCoreInstrumentationSources( } else { - builder.AddSource(HttpInListener.ActivitySourceName); + builder.AddSource(HttpInListener.ActivitySource.Name); builder.AddLegacySource(HttpInListener.ActivityOperationName); // for the activities created by AspNetCore } diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index c6813e4a42..ad59d8e052 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -11,6 +11,9 @@ * Updated OpenTelemetry core component version(s) to `1.15.2`. ([#4080](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4080)) +* Add instrumentation schema URL to traces. + ([#4066](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4066)) + ## 1.15.1 Released 2026-Mar-11 diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index c452c1fad9..f1cc009260 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -3,7 +3,6 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using System.Reflection; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; using OpenTelemetry.Context.Propagation; @@ -23,12 +22,7 @@ internal class HttpInListener : ListenerHandler // https://github.com/dotnet/aspnetcore/blob/8d6554e655b64da75b71e0e20d6db54a3ba8d2fb/src/Hosting/Hosting/src/GenericHost/GenericWebHostBuilder.cs#L85 internal const string AspNetCoreActivitySourceName = "Microsoft.AspNetCore"; - internal static readonly AssemblyName AssemblyName = typeof(HttpInListener).Assembly.GetName(); -#pragma warning disable IDE0370 // Suppression is unnecessary - internal static readonly string ActivitySourceName = AssemblyName.Name!; - internal static readonly Version Version = AssemblyName.Version!; -#pragma warning restore IDE0370 // Suppression is unnecessary - internal static readonly ActivitySource ActivitySource = new(ActivitySourceName, Version.ToString()); + internal static readonly ActivitySource ActivitySource = CreateActivitySource(); internal static readonly bool Net7OrGreater = Environment.Version.Major >= 7; private const string DiagnosticSourceName = "Microsoft.AspNetCore"; @@ -394,4 +388,24 @@ private static void AddGrpcAttributes(Activity activity, string grpcMethod, Http } } } + + private static ActivitySource CreateActivitySource() + { + const string telemetrySchemaUrl = "https://opentelemetry.io/schemas/1.40.0"; + + var assembly = typeof(HttpInListener).Assembly; + var assemblyName = assembly.GetName(); +#pragma warning disable IDE0370 // Suppression is unnecessary + var name = assemblyName.Name!; +#pragma warning restore IDE0370 // Suppression is unnecessary + var version = assembly.GetPackageVersion(); + + var activitySourceOptions = new ActivitySourceOptions(name) + { + TelemetrySchemaUrl = telemetrySchemaUrl, + Version = version, + }; + + return new ActivitySource(activitySourceOptions); + } } diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj b/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj index 9dc42087ae..a987658c87 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj @@ -13,15 +13,16 @@ - - - - - + + + + + + From 1567aab184be3282105bd0ec87aa6bf849153fe4 Mon Sep 17 00:00:00 2001 From: martincostello Date: Mon, 6 Apr 2026 17:12:32 +0100 Subject: [PATCH 2/6] [AspNetCore] Update tests Remove redundant test code for .NET Framework. --- .../BasicTests.cs | 7 ------- .../MetricTests.cs | 10 ---------- .../TestApplication/TestApplicationFactory.cs | 2 -- 3 files changed, 19 deletions(-) diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index 2e9d1b07d9..e2d2689d25 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -725,7 +725,6 @@ public async Task ActivitiesStartedInMiddlewareBySettingHostActivityToNullShould Assert.Equal("Microsoft.AspNetCore.Hosting.HttpRequestIn", aspnetcoreframeworkactivity.OperationName); } -#if NET [Fact] public async Task UserRegisteredActivitySourceIsUsedForActivityCreationByAspNetCore() { @@ -766,7 +765,6 @@ void ConfigureTestServices(IServiceCollection services) Assert.Equal("UserRegisteredActivitySource", activity.Source.Name); } -#endif [Theory] [InlineData(1)] @@ -1332,14 +1330,9 @@ private static void WaitForActivityExport(List exportedItems, int coun private static void ValidateAspNetCoreActivity(Activity activityToValidate, string expectedHttpPath) { Assert.Equal(ActivityKind.Server, activityToValidate.Kind); -#if NET Assert.Equal(HttpInListener.AspNetCoreActivitySourceName, activityToValidate.Source.Name); Assert.NotNull(activityToValidate.Source.Version); Assert.Empty(activityToValidate.Source.Version); -#else - Assert.Equal(HttpInListener.ActivitySourceName, activityToValidate.Source.Name); - Assert.Equal(HttpInListener.Version.ToString(), activityToValidate.Source.Version); -#endif Assert.Equal(expectedHttpPath, activityToValidate.GetTagValue(SemanticConventions.AttributeUrlPath) as string); } diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs index 0ea35508eb..48dd47f26a 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs @@ -1,22 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET using System.Threading.RateLimiting; using Microsoft.AspNetCore.Builder; -#endif using Microsoft.AspNetCore.Hosting; -#if NET using Microsoft.AspNetCore.Http; -#endif using Microsoft.AspNetCore.Mvc.Testing; -#if NET using Microsoft.AspNetCore.RateLimiting; -#endif -#if NET using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -#endif using Microsoft.Extensions.Logging; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -38,7 +30,6 @@ public void AddAspNetCoreInstrumentation_BadArgs() Assert.Throws(builder!.AddAspNetCoreInstrumentation); } -#if NET [Fact] public async Task ValidateNetMetricsAsync() { @@ -178,7 +169,6 @@ static string GetTicks() await app.DisposeAsync(); } -#endif [Theory] [InlineData("/api/values/2", "api/Values/{id}", null, 200)] diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/TestApplicationFactory.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/TestApplicationFactory.cs index a0e99e5775..478fe00c05 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/TestApplicationFactory.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/TestApplicationFactory.cs @@ -129,11 +129,9 @@ private static WebApplication CreateMinimalApiApplication() app.MapGet("/MinimalApi", () => Results.Ok()); app.MapGet("/MinimalApi/{id}", (int id) => Results.Ok()); -#if NET var api = app.MapGroup("/MinimalApiUsingMapGroup"); api.MapGet("/", () => Results.Ok()); api.MapGet("/{id}", (int id) => Results.Ok()); -#endif return app; } From f73911e800708681b63cf61bc6ba1e8cd0ab4141 Mon Sep 17 00:00:00 2001 From: martincostello Date: Mon, 6 Apr 2026 17:45:34 +0100 Subject: [PATCH 3/6] [AspNetCore] Address comments - Make CHANGELOG more specific. - Remove unused using statement. --- src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md | 2 +- .../MetricTests.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index ad59d8e052..823ef69ad2 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -11,7 +11,7 @@ * Updated OpenTelemetry core component version(s) to `1.15.2`. ([#4080](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4080)) -* Add instrumentation schema URL to traces. +* Add instrumentation schema URL to traces for `netstandard2.0`. ([#4066](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4066)) ## 1.15.1 diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs index 48dd47f26a..68853382f2 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.RateLimiting; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; From 5614b3bbc385b712c5c68a4c42bf2d15b6454c68 Mon Sep 17 00:00:00 2001 From: martincostello Date: Thu, 9 Apr 2026 10:38:43 +0100 Subject: [PATCH 4/6] [AspNetCore] Use ActivitySourceFactory Use `ActivitySourceFactory` to create the `Activity`. --- .../Implementation/HttpInListener.cs | 25 +++---------------- ...elemetry.Instrumentation.AspNetCore.csproj | 1 + 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index f1cc009260..468303f854 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -11,7 +11,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation; -internal class HttpInListener : ListenerHandler +internal sealed class HttpInListener : ListenerHandler { internal const string ActivityOperationName = "Microsoft.AspNetCore.Hosting.HttpRequestIn"; internal const string OnStartEvent = "Microsoft.AspNetCore.Hosting.HttpRequestIn.Start"; @@ -22,7 +22,8 @@ internal class HttpInListener : ListenerHandler // https://github.com/dotnet/aspnetcore/blob/8d6554e655b64da75b71e0e20d6db54a3ba8d2fb/src/Hosting/Hosting/src/GenericHost/GenericWebHostBuilder.cs#L85 internal const string AspNetCoreActivitySourceName = "Microsoft.AspNetCore"; - internal static readonly ActivitySource ActivitySource = CreateActivitySource(); + internal static readonly Version SemanticConventionsVersion = new(1, 40, 0); + internal static readonly ActivitySource ActivitySource = ActivitySourceFactory.Create(SemanticConventionsVersion); internal static readonly bool Net7OrGreater = Environment.Version.Major >= 7; private const string DiagnosticSourceName = "Microsoft.AspNetCore"; @@ -388,24 +389,4 @@ private static void AddGrpcAttributes(Activity activity, string grpcMethod, Http } } } - - private static ActivitySource CreateActivitySource() - { - const string telemetrySchemaUrl = "https://opentelemetry.io/schemas/1.40.0"; - - var assembly = typeof(HttpInListener).Assembly; - var assemblyName = assembly.GetName(); -#pragma warning disable IDE0370 // Suppression is unnecessary - var name = assemblyName.Name!; -#pragma warning restore IDE0370 // Suppression is unnecessary - var version = assembly.GetPackageVersion(); - - var activitySourceOptions = new ActivitySourceOptions(name) - { - TelemetrySchemaUrl = telemetrySchemaUrl, - Version = version, - }; - - return new ActivitySource(activitySourceOptions); - } } diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj b/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj index a987658c87..f941c259a8 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj @@ -15,6 +15,7 @@ + From 1e2cf4d0f0ee3a9f6d42b60b1cdbb7a1e585ec95 Mon Sep 17 00:00:00 2001 From: martincostello Date: Thu, 9 Apr 2026 11:04:34 +0100 Subject: [PATCH 5/6] [AspNetCore] Fix tests Revert `sealed`. --- .../Implementation/HttpInListener.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index 468303f854..4e4fc21163 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -11,7 +11,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation; -internal sealed class HttpInListener : ListenerHandler +internal class HttpInListener : ListenerHandler { internal const string ActivityOperationName = "Microsoft.AspNetCore.Hosting.HttpRequestIn"; internal const string OnStartEvent = "Microsoft.AspNetCore.Hosting.HttpRequestIn.Start"; From b5081fee6559ff307a4bd32878f36eaadd47d552 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Tue, 21 Apr 2026 18:09:22 +0100 Subject: [PATCH 6/6] [AspNetCore] Update CHANGELOG Move to unreleased. --- src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index f1cdb93e6a..e9081d6c18 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Add instrumentation schema URL to traces for `netstandard2.0`. + ([#4066](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4066)) + ## 1.15.2 Released 2026-Apr-21 @@ -15,9 +18,6 @@ Released 2026-Apr-21 * Updated OpenTelemetry core component version(s) to `1.15.3`. ([#4166](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4166)) -* Add instrumentation schema URL to traces for `netstandard2.0`. - ([#4066](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4066)) - ## 1.15.1 Released 2026-Mar-11