diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d4e898..5ab3a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.16.1] - 2024-12-18 + +### Changed + +- Aligned retry open telemetry attributes names with latest specification. [#324](https://github.com/microsoft/kiota-dotnet/issues/324) - Fixed a bug where the client would fail on 301/302 responses with no location headers. [#272](https://github.com/microsoft/kiota-dotnet/issues/272) ## [1.16.0] - 2024-12-13 diff --git a/Directory.Build.props b/Directory.Build.props index dd8db0b..f40df4e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.16.0 + 1.16.1 false diff --git a/src/http/httpClient/HttpClientRequestAdapter.cs b/src/http/httpClient/HttpClientRequestAdapter.cs index 00c403e..bc33b44 100644 --- a/src/http/httpClient/HttpClientRequestAdapter.cs +++ b/src/http/httpClient/HttpClientRequestAdapter.cs @@ -541,6 +541,8 @@ private async Task GetHttpResponseMessageAsync(RequestInfor /// public const string AuthenticateChallengedEventKey = "com.microsoft.kiota.authenticate_challenge_received"; + internal const string RetryCountAttributeName = "http.request.resend_count"; + private async Task RetryCAEResponseIfRequiredAsync(HttpResponseMessage response, RequestInformation requestInfo, CancellationToken cancellationToken, string? claims, Activity? activityForAttributes) { using var span = activitySource?.StartActivity(nameof(RetryCAEResponseIfRequiredAsync)); @@ -554,7 +556,7 @@ private async Task RetryCAEResponseIfRequiredAsync(HttpResp return response; } span?.AddEvent(new ActivityEvent(AuthenticateChallengedEventKey)); - activityForAttributes?.SetTag("http.retry_count", 1); + activityForAttributes?.SetTag(RetryCountAttributeName, 1); requestInfo.Content?.Seek(0, SeekOrigin.Begin); await DrainAsync(response, cancellationToken).ConfigureAwait(false); return await GetHttpResponseMessageAsync(requestInfo, cancellationToken, activityForAttributes, responseClaims).ConfigureAwait(false); diff --git a/src/http/httpClient/Middleware/RetryHandler.cs b/src/http/httpClient/Middleware/RetryHandler.cs index 4bed641..97fb414 100644 --- a/src/http/httpClient/Middleware/RetryHandler.cs +++ b/src/http/httpClient/Middleware/RetryHandler.cs @@ -105,11 +105,12 @@ 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(HttpClientRequestAdapter.RetryCountAttributeName, retryCount); 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); + var delay = DelayAsync(response, retryCount, retryOption.Delay, out double delayInSeconds, cancellationToken); + retryActivity?.SetTag("http.request.resend_delay", delayInSeconds); // If client specified a retries time limit, let's honor it if(retryOption.RetriesTimeLimit > TimeSpan.Zero) @@ -176,12 +177,12 @@ private static void AddOrUpdateRetryAttempt(HttpRequestMessage request, int retr /// /// The cancellationToken for the Http request /// The for delay operation. - internal static Task DelayAsync(HttpResponseMessage response, int retryCount, int delay, out double delayInSeconds, CancellationToken cancellationToken) + static internal Task DelayAsync(HttpResponseMessage response, int retryCount, int delay, out double delayInSeconds, CancellationToken cancellationToken) { delayInSeconds = delay; - if(response.Headers.TryGetValues(RetryAfter, out IEnumerable? values)) + if(response.Headers.TryGetValues(RetryAfter, out var values)) { - using IEnumerator v = values.GetEnumerator(); + using var v = values.GetEnumerator(); string retryAfter = v.MoveNext() ? v.Current : throw new InvalidOperationException("Retry-After header is empty."); // the delay could be in the form of a seconds or a http date. See https://httpwg.org/specs/rfc7231.html#header.retry-after if(int.TryParse(retryAfter, out int delaySeconds)) @@ -200,7 +201,7 @@ internal static Task DelayAsync(HttpResponseMessage response, int retryCount, in delayInSeconds = CalculateExponentialDelay(retryCount, delay); } - TimeSpan delayTimeSpan = TimeSpan.FromSeconds(Math.Min(delayInSeconds, RetryHandlerOption.MaxDelay)); + var delayTimeSpan = TimeSpan.FromSeconds(Math.Min(delayInSeconds, RetryHandlerOption.MaxDelay)); delayInSeconds = delayTimeSpan.TotalSeconds; return Task.Delay(delayTimeSpan, cancellationToken); }