From c5449a4f5dbc34c703d074e23ac09e750175e5ce Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 26 Oct 2023 11:23:36 -0700 Subject: [PATCH 1/3] add url.scheme to http.client.request.duration --- src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md | 5 +++++ .../Implementation/HttpHandlerMetricsDiagnosticListener.cs | 1 + .../Implementation/HttpWebRequestActivitySource.netfx.cs | 1 + .../HttpClientTests.cs | 3 ++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md index de1a8224da4..34ccffd46f2 100644 --- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md @@ -63,6 +63,11 @@ ([#4931](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4931)) + * Added `url.scheme` attribute to `http.client.request.duration` metric. The + metric will be emitted when `OTEL_SEMCONV_STABILITY_OPT_IN` is set to `http` + or `http/dup`. + ([]()) + ## 1.5.1-beta.1 Released 2023-Jul-20 diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs index f43e3c586de..0f2c53b588a 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs @@ -100,6 +100,7 @@ public override void OnEventWritten(string name, object payload) tags.Add(new KeyValuePair(SemanticConventions.AttributeHttpRequestMethod, HttpTagHelper.GetNameForHttpMethod(request.Method))); tags.Add(new KeyValuePair(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetFlavorTagValueFromProtocolVersion(request.Version))); tags.Add(new KeyValuePair(SemanticConventions.AttributeServerAddress, request.RequestUri.Host)); + tags.Add(new KeyValuePair(SemanticConventions.AttributeUrlScheme, request.RequestUri.Scheme)); if (!request.RequestUri.IsDefaultPort) { diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs index d341ebbcf14..2cb52a8bbd6 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs @@ -497,6 +497,7 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC tags.Add(SemanticConventions.AttributeHttpRequestMethod, request.Method); tags.Add(SemanticConventions.AttributeServerAddress, request.RequestUri.Host); + tags.Add(SemanticConventions.AttributeUrlScheme, request.RequestUri.Scheme); tags.Add(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetFlavorTagValueFromProtocolVersion(request.ProtocolVersion)); if (!request.RequestUri.IsDefaultPort) { diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.cs index 4629e9a036f..63fb2e65b8a 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.cs @@ -519,7 +519,7 @@ private static async Task HttpOutCallsAreCollectedSuccessfullyBodyAsync( attributes[tag.Key] = tag.Value; } - var expectedAttributeCount = 4 + (tc.ResponseExpected ? 1 : 0); + var expectedAttributeCount = 5 + (tc.ResponseExpected ? 1 : 0); Assert.Equal(expectedAttributeCount, attributes.Count); @@ -527,6 +527,7 @@ private static async Task HttpOutCallsAreCollectedSuccessfullyBodyAsync( Assert.Contains(attributes, kvp => kvp.Key == SemanticConventions.AttributeServerAddress && kvp.Value.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeNetPeerName]); Assert.Contains(attributes, kvp => kvp.Key == SemanticConventions.AttributeServerPort && kvp.Value.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeNetPeerPort]); Assert.Contains(attributes, kvp => kvp.Key == SemanticConventions.AttributeNetworkProtocolVersion && kvp.Value.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeHttpFlavor]); + Assert.Contains(attributes, kvp => kvp.Key == SemanticConventions.AttributeUrlScheme && kvp.Value.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeHttpScheme]); if (tc.ResponseExpected) { Assert.Contains(attributes, kvp => kvp.Key == SemanticConventions.AttributeHttpResponseStatusCode && kvp.Value.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeHttpStatusCode]); From 52a64718411b82f19779f0b01e72680d31bf3974 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 26 Oct 2023 11:25:45 -0700 Subject: [PATCH 2/3] edit changelog --- src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md index 34ccffd46f2..a020bada0eb 100644 --- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md @@ -66,7 +66,7 @@ * Added `url.scheme` attribute to `http.client.request.duration` metric. The metric will be emitted when `OTEL_SEMCONV_STABILITY_OPT_IN` is set to `http` or `http/dup`. - ([]()) + ([#4989](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4989)) ## 1.5.1-beta.1 From 0d4ffdecbec7ec9e7a1594db237c9d4dbe47c910 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 26 Oct 2023 11:27:21 -0700 Subject: [PATCH 3/3] nit --- src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md index a020bada0eb..0853c295ba4 100644 --- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md @@ -64,8 +64,8 @@ ([#4931](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4931)) * Added `url.scheme` attribute to `http.client.request.duration` metric. The - metric will be emitted when `OTEL_SEMCONV_STABILITY_OPT_IN` is set to `http` - or `http/dup`. + metric will be emitted when `OTEL_SEMCONV_STABILITY_OPT_IN` environment + variable is set to `http` or `http/dup`. ([#4989](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4989)) ## 1.5.1-beta.1