Skip to content

Commit

Permalink
[Instrumentation.AspNetCore] metrics - cleanup code after dropping su…
Browse files Browse the repository at this point in the history
…pport for .NET6 (#2360)
  • Loading branch information
Kielek authored Dec 9, 2024
1 parent e4f3b05 commit 3964894
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 238 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#if !NET
using OpenTelemetry.Instrumentation.AspNetCore;
using OpenTelemetry.Instrumentation.AspNetCore.Implementation;
#endif
using OpenTelemetry.Internal;

namespace OpenTelemetry.Metrics;
Expand All @@ -22,27 +18,15 @@ public static class AspNetCoreInstrumentationMeterProviderBuilderExtensions
public static MeterProviderBuilder AddAspNetCoreInstrumentation(
this MeterProviderBuilder builder)
{
Guard.ThrowIfNull(builder);

#if NET
return builder.ConfigureMeters();
#else
// Note: Warm-up the status code and method mapping.
_ = TelemetryHelper.BoxedStatusCodes;
_ = TelemetryHelper.RequestDataHelper;

builder.AddMeter(HttpInMetricsListener.InstrumentationName);
#if NETSTANDARD2_0_OR_GREATER
if (Environment.Version.Major < 8)
{
throw new PlatformNotSupportedException("Metrics instrumentation is not supported when executing on .NET 7 and lower.");
}

#pragma warning disable CA2000
builder.AddInstrumentation(new AspNetCoreMetrics());
#pragma warning restore CA2000

return builder;
#endif
}
Guard.ThrowIfNull(builder);

internal static MeterProviderBuilder ConfigureMeters(this MeterProviderBuilder builder)
{
return builder
.AddMeter("Microsoft.AspNetCore.Hosting")
.AddMeter("Microsoft.AspNetCore.Server.Kestrel")
Expand Down
41 changes: 0 additions & 41 deletions src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreMetrics.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Unreleased

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

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

This file was deleted.

31 changes: 0 additions & 31 deletions src/OpenTelemetry.Instrumentation.AspNetCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,8 @@ public void ConfigureServices(IServiceCollection services)
}
```

Following list of attributes are added by default on
`http.server.request.duration` metric. See
[http-metrics](https://github.com/open-telemetry/semantic-conventions/tree/v1.23.0/docs/http/http-metrics.md)
for more details about each individual attribute. `.NET8.0` and above supports
additional metrics, see [list of metrics produced](#list-of-metrics-produced) for
more details.

* `error.type`
* `http.response.status_code`
* `http.request.method`
* `http.route`
* `network.protocol.version`
* `url.scheme`

#### List of metrics produced

When the application targets `.NET6.0` or `.NET7.0`, the instrumentation emits
the following metric:

| Name | Details |
|-----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| `http.server.request.duration` | [Specification](https://github.com/open-telemetry/semantic-conventions/blob/release/v1.23.x/docs/http/http-metrics.md#metric-httpserverrequestduration) |

Starting from `.NET8.0`, metrics instrumentation is natively implemented, and
the ASP.NET Core library has incorporated support for [built-in
metrics](https://learn.microsoft.com/dotnet/core/diagnostics/built-in-metrics-aspnetcore)
Expand Down Expand Up @@ -164,16 +143,6 @@ to achieve this.
> There is no difference in features or emitted metrics when enabling metrics
using `AddMeter()` or `AddAspNetCoreInstrumentation()` on `.NET8.0` and newer
versions.
<!-- This comment is to make sure the two notes above and below are not merged -->
> [!NOTE]
> The `http.server.request.duration` metric is emitted in `seconds` as per the
semantic convention. While the convention [recommends using custom histogram
buckets](https://github.com/open-telemetry/semantic-conventions/blob/release/v1.23.x/docs/http/http-metrics.md)
, this feature is not yet available via .NET Metrics API. A
[workaround](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4820)
has been included in OTel SDK starting version `1.6.0` which applies recommended
buckets by default for `http.server.request.duration`. This applies to all
targeted frameworks.

## Advanced configuration

Expand Down
11 changes: 0 additions & 11 deletions test/OpenTelemetry.Instrumentation.AspNetCore.Tests/MetricTests.cs
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 ValidateNet8MetricsAsync()
{
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

0 comments on commit 3964894

Please sign in to comment.