Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CosmosClient: Fixes missing Trace when converting HTTP Timeout to 503 #3866

Merged
14 commits merged into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Microsoft.Azure.Cosmos
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Core.Trace;
using Microsoft.Azure.Cosmos.Resource.CosmosExceptions;
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.Azure.Cosmos.Tracing.TraceData;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Collections;
Expand Down Expand Up @@ -307,20 +308,25 @@ public override Task<HttpResponseMessage> SendHttpAsync(
throw new ArgumentNullException(nameof(createRequestMessageAsync));
}

return this.SendHttpHelperAsync(
createRequestMessageAsync,
resourceType,
timeoutPolicy,
clientSideRequestStatistics,
cancellationToken);
using (ITrace trace = Trace.GetRootTrace(nameof(SendHttpAsync), TraceComponent.Transport, TraceLevel.Info))
rinatmini marked this conversation as resolved.
Show resolved Hide resolved
{
return this.SendHttpHelperAsync(
createRequestMessageAsync,
resourceType,
timeoutPolicy,
clientSideRequestStatistics,
cancellationToken,
trace);
}
}

private async Task<HttpResponseMessage> SendHttpHelperAsync(
Func<ValueTask<HttpRequestMessage>> createRequestMessageAsync,
ResourceType resourceType,
HttpTimeoutPolicy timeoutPolicy,
IClientSideRequestStatistics clientSideRequestStatistics,
CancellationToken cancellationToken)
CancellationToken cancellationToken,
ITrace trace)
rinatmini marked this conversation as resolved.
Show resolved Hide resolved
{
DateTime startDateTimeUtc = DateTime.UtcNow;
IEnumerator<(TimeSpan requestTimeout, TimeSpan delayForNextRequest)> timeoutEnumerator = timeoutPolicy.GetTimeoutEnumerator();
Expand Down Expand Up @@ -387,13 +393,15 @@ private async Task<HttpResponseMessage> SendHttpHelperAsync(

if (timeoutPolicy.ShouldThrow503OnTimeout)
{
trace.AddDatum("Client Side Request Stats", clientSideRequestStatistics);
rinatmini marked this conversation as resolved.
Show resolved Hide resolved
throw CosmosExceptionFactory.CreateServiceUnavailableException(
message: message,
headers: new Headers()
{
ActivityId = System.Diagnostics.Trace.CorrelationManager.ActivityId.ToString(),
SubStatusCode = SubStatusCodes.TransportGenerated503
},
trace: trace,
innerException: e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ async Task<HttpResponseMessage> sendFunc(HttpRequestMessage request, Cancellatio
CosmosException cosmosException = (CosmosException)e;
rinatmini marked this conversation as resolved.
Show resolved Hide resolved
Assert.AreEqual(cosmosException.StatusCode, System.Net.HttpStatusCode.ServiceUnavailable);
Assert.AreEqual((int)cosmosException.SubStatusCode,(int)SubStatusCodes.TransportGenerated503);

Assert.IsNotNull(cosmosException.Trace);
Assert.AreNotEqual(cosmosException.Trace.Data.Count, 0);
}
}

Expand Down