From e943d589d0e2699e1c16f2ebf23fca39cb1dc0c3 Mon Sep 17 00:00:00 2001 From: Kevin Boonstra <23527353+Strazz1337@users.noreply.github.com> Date: Thu, 10 Oct 2024 21:11:51 +0200 Subject: [PATCH 1/2] fix(spans): adhere attribute name to otel semver --- .../httpClient/HttpClientRequestAdapter.cs | 22 +++++++++---------- .../httpClient/Middleware/RedirectHandler.cs | 2 +- .../httpClient/Middleware/RetryHandler.cs | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/http/httpClient/HttpClientRequestAdapter.cs b/src/http/httpClient/HttpClientRequestAdapter.cs index 4ec4906e..05314d5b 100644 --- a/src/http/httpClient/HttpClientRequestAdapter.cs +++ b/src/http/httpClient/HttpClientRequestAdapter.cs @@ -78,7 +78,7 @@ public string? BaseUrl var decodedUriTemplate = ParametersNameDecodingHandler.DecodeUriEncodedString(requestInfo.UrlTemplate, charactersToDecodeForUriTemplate); var telemetryPathValue = string.IsNullOrEmpty(decodedUriTemplate) ? string.Empty : queryParametersCleanupRegex.Replace(decodedUriTemplate, string.Empty); var span = activitySource?.StartActivity($"{methodName} - {telemetryPathValue}"); - span?.SetTag("http.uri_template", decodedUriTemplate); + span?.SetTag("url.uri_template", decodedUriTemplate); return span; } /// @@ -519,7 +519,7 @@ private async Task GetHttpResponseMessageAsync(RequestInfor using var contentLengthEnumerator = contentLengthValues.GetEnumerator(); if(contentLengthEnumerator.MoveNext() && int.TryParse(contentLengthEnumerator.Current, out var contentLength)) { - activityForAttributes?.SetTag("http.response_content_length", contentLength); + activityForAttributes?.SetTag("http.response.body.size", contentLength); } } if(response.Headers.TryGetValues("Content-Type", out var contentTypeValues)) @@ -527,11 +527,11 @@ private async Task GetHttpResponseMessageAsync(RequestInfor using var contentTypeEnumerator = contentTypeValues.GetEnumerator(); if(contentTypeEnumerator.MoveNext()) { - activityForAttributes?.SetTag("http.response_content_type", contentTypeEnumerator.Current); + activityForAttributes?.SetTag("http.response.header.content-type", contentTypeEnumerator.Current); } } - activityForAttributes?.SetTag("http.status_code", (int)response.StatusCode); - activityForAttributes?.SetTag("http.flavor", $"{response.Version.Major}.{response.Version.Minor}"); + activityForAttributes?.SetTag("http.response.status_code", (int)response.StatusCode); + activityForAttributes?.SetTag("network.protocol.name", $"{response.Version.Major}.{response.Version.Minor}"); return await RetryCAEResponseIfRequiredAsync(response, requestInfo, cancellationToken, claims, activityForAttributes).ConfigureAwait(false); } @@ -612,12 +612,12 @@ private HttpRequestMessage GetRequestMessageFromRequestInformation(RequestInform { using var span = activitySource?.StartActivity(nameof(GetRequestMessageFromRequestInformation)); SetBaseUrlForRequestInformation(requestInfo);// this method can also be called from a different context so ensure the baseUrl is added. - activityForAttributes?.SetTag("http.method", requestInfo.HttpMethod.ToString()); + activityForAttributes?.SetTag("http.request.method", requestInfo.HttpMethod.ToString()); var requestUri = requestInfo.URI; - activityForAttributes?.SetTag("http.host", requestUri.Host); - activityForAttributes?.SetTag("http.scheme", requestUri.Scheme); + activityForAttributes?.SetTag("url.scheme", requestUri.Host); + activityForAttributes?.SetTag("server.address", requestUri.Scheme); if(obsOptions.IncludeEUIIAttributes) - activityForAttributes?.SetTag("http.uri", requestUri.ToString()); + activityForAttributes?.SetTag("url.full", requestUri.ToString()); var message = new HttpRequestMessage { Method = new HttpMethod(requestInfo.HttpMethod.ToString().ToUpperInvariant()), @@ -653,13 +653,13 @@ private HttpRequestMessage GetRequestMessageFromRequestInformation(RequestInform { var contentLenEnumerator = contentLenValues.GetEnumerator(); if(contentLenEnumerator.MoveNext() && int.TryParse(contentLenEnumerator.Current, out var contentLenValueInt)) - activityForAttributes?.SetTag("http.request_content_length", contentLenValueInt); + activityForAttributes?.SetTag("http.request.body.size", contentLenValueInt); } if(message.Content.Headers.TryGetValues("Content-Type", out var contentTypeValues)) { var contentTypeEnumerator = contentTypeValues.GetEnumerator(); if(contentTypeEnumerator.MoveNext()) - activityForAttributes?.SetTag("http.request_content_type", contentTypeEnumerator.Current); + activityForAttributes?.SetTag("http.request.header.content-type", contentTypeEnumerator.Current); } } return message; diff --git a/src/http/httpClient/Middleware/RedirectHandler.cs b/src/http/httpClient/Middleware/RedirectHandler.cs index 07cc8718..2c4d37f4 100644 --- a/src/http/httpClient/Middleware/RedirectHandler.cs +++ b/src/http/httpClient/Middleware/RedirectHandler.cs @@ -82,7 +82,7 @@ protected override async Task SendAsync(HttpRequestMessage { using var redirectActivity = activitySource?.StartActivity($"{nameof(RedirectHandler)}_{nameof(SendAsync)} - redirect {redirectCount}"); redirectActivity?.SetTag("com.microsoft.kiota.handler.redirect.count", redirectCount); - redirectActivity?.SetTag("http.status_code", response.StatusCode); + redirectActivity?.SetTag("http.response.status_code", response.StatusCode); // Drain response content to free responses. if(response.Content != null) { diff --git a/src/http/httpClient/Middleware/RetryHandler.cs b/src/http/httpClient/Middleware/RetryHandler.cs index 4c1d1dac..4bed641c 100644 --- a/src/http/httpClient/Middleware/RetryHandler.cs +++ b/src/http/httpClient/Middleware/RetryHandler.cs @@ -106,7 +106,7 @@ private async Task SendRetryAsync(HttpResponseMessage respo exceptions.Add(await GetInnerExceptionAsync(response).ConfigureAwait(false)); using var retryActivity = activitySource?.StartActivity($"{nameof(RetryHandler)}_{nameof(SendAsync)} - attempt {retryCount}"); retryActivity?.SetTag("http.retry_count", retryCount); - retryActivity?.SetTag("http.status_code", response.StatusCode); + retryActivity?.SetTag("http.response.status_code", response.StatusCode); // Call Delay method to get delay time from response's Retry-After header or by exponential backoff Task delay = RetryHandler.DelayAsync(response, retryCount, retryOption.Delay, out double delayInSeconds, cancellationToken); From 58496faa4b4d267add4db7a1b8f4f697c91e7488 Mon Sep 17 00:00:00 2001 From: Kevin Boonstra <23527353+Strazz1337@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:19:34 +0200 Subject: [PATCH 2/2] chore: bump version to 1.13.1 --- CHANGELOG.md | 6 ++++++ Directory.Build.props | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a61895c4..97f7edec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.13.1] - 2024-10-10 + +### Changed + +- Updated HTTP span attributes to comply with updated OpenTelemetry semantic conventions. [#344](https://github.com/microsoft/kiota-dotnet/issues/344) + ## [1.13.0] - 2024-09-25 ### Changed diff --git a/Directory.Build.props b/Directory.Build.props index 9b7955bd..bfec8f62 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.13.0 + 1.13.1 false