Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* Fix `http.route` for the root path for Razor Pages.
([#4016](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4016))

* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\Shared\Configuration\*.cs" Link="Includes\Configuration\%(Filename).cs" />
<Compile Include="$(RepoRoot)\src\Shared\EnvironmentVariables\*.cs" Link="Includes\EnvironmentVariables\%(Filename).cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
<Compile Include="$(RepoRoot)\src\Shared\GrpcTagHelper.cs" Link="Includes\GrpcTagHelper.cs" />
<Compile Include="$(RepoRoot)\src\Shared\GrpcStatusCanonicalCode.cs" Link="Includes\GrpcStatusCanonicalCode.cs" />
<Compile Include="$(RepoRoot)\src\Shared\ActivityHelperExtensions.cs" Link="Includes\ActivityHelperExtensions.cs" />
<Compile Include="$(RepoRoot)\src\Shared\ActivityInstrumentationHelper.cs" Link="Includes\ActivityInstrumentationHelper.cs" />
<Compile Include="$(RepoRoot)\src\Shared\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\Shared\AssemblyVersionExtensions.cs" Link="Includes\AssemblyVersionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\Shared\Configuration\*.cs" Link="Includes\Configuration\%(Filename).cs" />
<Compile Include="$(RepoRoot)\src\Shared\DiagnosticSourceListener.cs" Link="Includes\DiagnosticSourceListener.cs" />
<Compile Include="$(RepoRoot)\src\Shared\DiagnosticSourceSubscriber.cs" Link="Includes\DiagnosticSourceSubscriber.cs" />
<Compile Include="$(RepoRoot)\src\Shared\EnvironmentVariables\*.cs" Link="Includes\EnvironmentVariables\%(Filename).cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
<Compile Include="$(RepoRoot)\src\Shared\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\Shared\GrpcTagHelper.cs" Link="Includes\GrpcTagHelper.cs" />
<Compile Include="$(RepoRoot)\src\Shared\GrpcStatusCanonicalCode.cs" Link="Includes\GrpcStatusCanonicalCode.cs" />
<Compile Include="$(RepoRoot)\src\Shared\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\Shared\ListenerHandler.cs" Link="Includes\ListenerHandler.cs" />
<Compile Include="$(RepoRoot)\src\Shared\NullableAttributes.cs" Link="Includes\NullableAttributes.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,6 @@ public async Task ActivitiesStartedInMiddlewareBySettingHostActivityToNullShould
Assert.Equal("Microsoft.AspNetCore.Hosting.HttpRequestIn", aspnetcoreframeworkactivity.OperationName);
}

#if NET
[Fact]
public async Task UserRegisteredActivitySourceIsUsedForActivityCreationByAspNetCore()
{
Expand Down Expand Up @@ -766,7 +765,6 @@ void ConfigureTestServices(IServiceCollection services)

Assert.Equal("UserRegisteredActivitySource", activity.Source.Name);
}
#endif

[Theory]
[InlineData(1)]
Expand Down Expand Up @@ -1332,14 +1330,9 @@ private static void WaitForActivityExport(List<Activity> 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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
// 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;
Expand All @@ -38,7 +29,6 @@ public void AddAspNetCoreInstrumentation_BadArgs()
Assert.Throws<ArgumentNullException>(builder!.AddAspNetCoreInstrumentation);
}

#if NET
[Fact]
public async Task ValidateNetMetricsAsync()
{
Expand Down Expand Up @@ -178,7 +168,6 @@ static string GetTicks()

await app.DisposeAsync();
}
#endif

[Theory]
[InlineData("/api/values/2", "api/Values/{id}", null, 200)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading