Skip to content

Commit cbba3d6

Browse files
committed
Keep workaround only in HttpInListener
1 parent 5b97fe8 commit cbba3d6

File tree

4 files changed

+9
-26
lines changed

4 files changed

+9
-26
lines changed

src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationMeterProviderBuilderExtensions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ public static MeterProviderBuilder AddAspNetCoreInstrumentation(
2727
#if NET8_0_OR_GREATER
2828
return builder.ConfigureMeters();
2929
#else
30-
if (Environment.Version.Major >= 8)
31-
{
32-
return builder.ConfigureMeters();
33-
}
34-
3530
// Note: Warm-up the status code and method mapping.
3631
_ = TelemetryHelper.BoxedStatusCodes;
3732
_ = RequestMethodHelper.KnownMethods;

src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationTracerProviderBuilderExtensions.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#if NET7_0_OR_GREATER
45
using System.Diagnostics;
6+
#endif
57
using Microsoft.Extensions.DependencyInjection;
68
using Microsoft.Extensions.Options;
79
using OpenTelemetry.Instrumentation.AspNetCore;
@@ -99,11 +101,7 @@ private static void AddAspNetCoreInstrumentationSources(
99101
// For .NET7.0 onwards activity will be created using activitySource.
100102
// https://github.com/dotnet/aspnetcore/blob/bf3352f2422bf16fa3ca49021f0e31961ce525eb/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs#L327
101103
// For .NET6.0 and below, we will continue to use legacy way.
102-
103-
#if !NET7_0_OR_GREATER
104-
if (HttpInListener.Net7OrGreater)
105-
{
106-
#endif
104+
#if NET7_0_OR_GREATER
107105
// TODO: Check with .NET team to see if this can be prevented
108106
// as this allows user to override the ActivitySource.
109107
var activitySourceService = serviceProvider?.GetService<ActivitySource>();
@@ -116,13 +114,9 @@ private static void AddAspNetCoreInstrumentationSources(
116114
// For users not using hosting package?
117115
builder.AddSource(HttpInListener.AspNetCoreActivitySourceName);
118116
}
119-
#if !NET7_0_OR_GREATER
120-
}
121-
else
122-
{
123-
builder.AddSource(HttpInListener.ActivitySourceName);
124-
builder.AddLegacySource(HttpInListener.ActivityOperationName); // for the activities created by AspNetCore
125-
}
117+
#else
118+
builder.AddSource(HttpInListener.ActivitySourceName);
119+
builder.AddLegacySource(HttpInListener.ActivityOperationName); // for the activities created by AspNetCore
126120
#endif
127121
}
128122
}

src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
instance obtained from `IHttpActivityFeature.Activity`.
99
([#5136](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5136))
1010

11-
* Fixed metrics instrumentation when library targeting .NET 6 or .NET 7
12-
was loaded by .NET 8.
13-
Fixed traces instrumentation when library targeting .NET 6
14-
was loaded by .NET 7 or .NET 8.
15-
([#5252](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5252))
16-
1711
* Fixed an issue where the `http.route` attribute was not set on either the
1812
`Activity` or `http.server.request.duration` metric generated from a
1913
request when an exception handling middleware is invoked. One caveat is that

src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ internal class HttpInListener : ListenerHandler
3535
internal static readonly Version Version = AssemblyName.Version;
3636
internal static readonly ActivitySource ActivitySource = new(ActivitySourceName, Version.ToString());
3737

38+
private const string DiagnosticSourceName = "Microsoft.AspNetCore";
39+
3840
#if !NET7_0_OR_GREATER
39-
internal static readonly bool Net7OrGreater = Environment.Version.Major >= 7;
41+
private static readonly bool Net7OrGreater = Environment.Version.Major >= 7;
4042
#endif
4143

42-
private const string DiagnosticSourceName = "Microsoft.AspNetCore";
43-
4444
private static readonly Func<HttpRequest, string, IEnumerable<string>> HttpRequestHeaderValuesGetter = (request, name) =>
4545
{
4646
if (request.Headers.TryGetValue(name, out var value))

0 commit comments

Comments
 (0)