Skip to content

Commit 3964894

Browse files
authored
[Instrumentation.AspNetCore] metrics - cleanup code after dropping support for .NET6 (#2360)
1 parent e4f3b05 commit 3964894

File tree

6 files changed

+8
-238
lines changed

6 files changed

+8
-238
lines changed

src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationMeterProviderBuilderExtensions.cs

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

4-
#if !NET
5-
using OpenTelemetry.Instrumentation.AspNetCore;
6-
using OpenTelemetry.Instrumentation.AspNetCore.Implementation;
7-
#endif
84
using OpenTelemetry.Internal;
95

106
namespace OpenTelemetry.Metrics;
@@ -22,27 +18,15 @@ public static class AspNetCoreInstrumentationMeterProviderBuilderExtensions
2218
public static MeterProviderBuilder AddAspNetCoreInstrumentation(
2319
this MeterProviderBuilder builder)
2420
{
25-
Guard.ThrowIfNull(builder);
26-
27-
#if NET
28-
return builder.ConfigureMeters();
29-
#else
30-
// Note: Warm-up the status code and method mapping.
31-
_ = TelemetryHelper.BoxedStatusCodes;
32-
_ = TelemetryHelper.RequestDataHelper;
33-
34-
builder.AddMeter(HttpInMetricsListener.InstrumentationName);
21+
#if NETSTANDARD2_0_OR_GREATER
22+
if (Environment.Version.Major < 8)
23+
{
24+
throw new PlatformNotSupportedException("Metrics instrumentation is not supported when executing on .NET 7 and lower.");
25+
}
3526

36-
#pragma warning disable CA2000
37-
builder.AddInstrumentation(new AspNetCoreMetrics());
38-
#pragma warning restore CA2000
39-
40-
return builder;
4127
#endif
42-
}
28+
Guard.ThrowIfNull(builder);
4329

44-
internal static MeterProviderBuilder ConfigureMeters(this MeterProviderBuilder builder)
45-
{
4630
return builder
4731
.AddMeter("Microsoft.AspNetCore.Hosting")
4832
.AddMeter("Microsoft.AspNetCore.Server.Kestrel")

src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreMetrics.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## Unreleased
44

55
* Drop support for .NET 6 as this target is no longer supported.
6-
([#2138](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2138))
6+
([#2138](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2138),
7+
([#2360](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2360))
78

89
* Updated OpenTelemetry core component version(s) to `1.10.0`.
910
([#2317](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2317))

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

Lines changed: 0 additions & 132 deletions
This file was deleted.

src/OpenTelemetry.Instrumentation.AspNetCore/README.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,8 @@ public void ConfigureServices(IServiceCollection services)
113113
}
114114
```
115115

116-
Following list of attributes are added by default on
117-
`http.server.request.duration` metric. See
118-
[http-metrics](https://github.com/open-telemetry/semantic-conventions/tree/v1.23.0/docs/http/http-metrics.md)
119-
for more details about each individual attribute. `.NET8.0` and above supports
120-
additional metrics, see [list of metrics produced](#list-of-metrics-produced) for
121-
more details.
122-
123-
* `error.type`
124-
* `http.response.status_code`
125-
* `http.request.method`
126-
* `http.route`
127-
* `network.protocol.version`
128-
* `url.scheme`
129-
130116
#### List of metrics produced
131117

132-
When the application targets `.NET6.0` or `.NET7.0`, the instrumentation emits
133-
the following metric:
134-
135-
| Name | Details |
136-
|-----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
137-
| `http.server.request.duration` | [Specification](https://github.com/open-telemetry/semantic-conventions/blob/release/v1.23.x/docs/http/http-metrics.md#metric-httpserverrequestduration) |
138-
139118
Starting from `.NET8.0`, metrics instrumentation is natively implemented, and
140119
the ASP.NET Core library has incorporated support for [built-in
141120
metrics](https://learn.microsoft.com/dotnet/core/diagnostics/built-in-metrics-aspnetcore)
@@ -164,16 +143,6 @@ to achieve this.
164143
> There is no difference in features or emitted metrics when enabling metrics
165144
using `AddMeter()` or `AddAspNetCoreInstrumentation()` on `.NET8.0` and newer
166145
versions.
167-
<!-- This comment is to make sure the two notes above and below are not merged -->
168-
> [!NOTE]
169-
> The `http.server.request.duration` metric is emitted in `seconds` as per the
170-
semantic convention. While the convention [recommends using custom histogram
171-
buckets](https://github.com/open-telemetry/semantic-conventions/blob/release/v1.23.x/docs/http/http-metrics.md)
172-
, this feature is not yet available via .NET Metrics API. A
173-
[workaround](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4820)
174-
has been included in OTel SDK starting version `1.6.0` which applies recommended
175-
buckets by default for `http.server.request.duration`. This applies to all
176-
targeted frameworks.
177146

178147
## Advanced configuration
179148

test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs

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

4-
#if NET
54
using System.Threading.RateLimiting;
65
using Microsoft.AspNetCore.Builder;
7-
#endif
86
using Microsoft.AspNetCore.Hosting;
9-
#if NET
107
using Microsoft.AspNetCore.Http;
11-
#endif
128
using Microsoft.AspNetCore.Mvc.Testing;
13-
#if NET
149
using Microsoft.AspNetCore.RateLimiting;
15-
#endif
16-
#if NET
1710
using Microsoft.Extensions.DependencyInjection;
18-
using Microsoft.Extensions.Hosting;
19-
#endif
2011
using Microsoft.Extensions.Logging;
2112
using OpenTelemetry.Metrics;
2213
using OpenTelemetry.Trace;
@@ -38,7 +29,6 @@ public void AddAspNetCoreInstrumentation_BadArgs()
3829
Assert.Throws<ArgumentNullException>(builder!.AddAspNetCoreInstrumentation);
3930
}
4031

41-
#if NET
4232
[Fact]
4333
public async Task ValidateNet8MetricsAsync()
4434
{
@@ -178,7 +168,6 @@ static string GetTicks()
178168

179169
await app.DisposeAsync();
180170
}
181-
#endif
182171

183172
[Theory]
184173
[InlineData("/api/values/2", "api/Values/{id}", null, 200)]

0 commit comments

Comments
 (0)