Skip to content

Commit

Permalink
Keep workaround only in HttpInListener
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Jan 31, 2024
1 parent 5b97fe8 commit cbba3d6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public static MeterProviderBuilder AddAspNetCoreInstrumentation(
#if NET8_0_OR_GREATER
return builder.ConfigureMeters();
#else
if (Environment.Version.Major >= 8)
{
return builder.ConfigureMeters();
}

// Note: Warm-up the status code and method mapping.
_ = TelemetryHelper.BoxedStatusCodes;
_ = RequestMethodHelper.KnownMethods;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#if NET7_0_OR_GREATER
using System.Diagnostics;
#endif
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenTelemetry.Instrumentation.AspNetCore;
Expand Down Expand Up @@ -99,11 +101,7 @@ private static void AddAspNetCoreInstrumentationSources(
// For .NET7.0 onwards activity will be created using activitySource.
// https://github.com/dotnet/aspnetcore/blob/bf3352f2422bf16fa3ca49021f0e31961ce525eb/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs#L327
// For .NET6.0 and below, we will continue to use legacy way.

#if !NET7_0_OR_GREATER
if (HttpInListener.Net7OrGreater)
{
#endif
#if NET7_0_OR_GREATER
// TODO: Check with .NET team to see if this can be prevented
// as this allows user to override the ActivitySource.
var activitySourceService = serviceProvider?.GetService<ActivitySource>();
Expand All @@ -116,13 +114,9 @@ private static void AddAspNetCoreInstrumentationSources(
// For users not using hosting package?
builder.AddSource(HttpInListener.AspNetCoreActivitySourceName);
}
#if !NET7_0_OR_GREATER
}
else
{
builder.AddSource(HttpInListener.ActivitySourceName);
builder.AddLegacySource(HttpInListener.ActivityOperationName); // for the activities created by AspNetCore
}
#else
builder.AddSource(HttpInListener.ActivitySourceName);
builder.AddLegacySource(HttpInListener.ActivityOperationName); // for the activities created by AspNetCore
#endif
}
}
6 changes: 0 additions & 6 deletions src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
instance obtained from `IHttpActivityFeature.Activity`.
([#5136](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5136))

* Fixed metrics instrumentation when library targeting .NET 6 or .NET 7
was loaded by .NET 8.
Fixed traces instrumentation when library targeting .NET 6
was loaded by .NET 7 or .NET 8.
([#5252](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5252))

* Fixed an issue where the `http.route` attribute was not set on either the
`Activity` or `http.server.request.duration` metric generated from a
request when an exception handling middleware is invoked. One caveat is that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ internal class HttpInListener : ListenerHandler
internal static readonly Version Version = AssemblyName.Version;
internal static readonly ActivitySource ActivitySource = new(ActivitySourceName, Version.ToString());

private const string DiagnosticSourceName = "Microsoft.AspNetCore";

#if !NET7_0_OR_GREATER
internal static readonly bool Net7OrGreater = Environment.Version.Major >= 7;
private static readonly bool Net7OrGreater = Environment.Version.Major >= 7;
#endif

private const string DiagnosticSourceName = "Microsoft.AspNetCore";

private static readonly Func<HttpRequest, string, IEnumerable<string>> HttpRequestHeaderValuesGetter = (request, name) =>
{
if (request.Headers.TryGetValue(name, out var value))
Expand Down

0 comments on commit cbba3d6

Please sign in to comment.