Skip to content

Commit

Permalink
[Internal] Distributed Tracing: Fixes Client Config Test (#4406) (#4418)
Browse files Browse the repository at this point in the history
* Adds code to create activity even customer is not subscribed to the feature

* Added documentation
  • Loading branch information
sourabh1007 authored Apr 15, 2024
1 parent b44f3bd commit f25967a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,19 @@ public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
clientContext: clientContext,
config: requestOptions?.CosmosThresholdOptions ?? clientContext.ClientOptions?.CosmosClientTelemetryOptions.CosmosThresholdOptions);
}

#if !INTERNAL
// If there are no listeners at operation level and no parent activity created.
// Then create a dummy activity as there should be a parent level activity always to send a traceid to the backend services through context propagation.
// The parent activity id logged in diagnostics, can be used for tracing purpose in backend.
if (Activity.Current is null)
{
openTelemetryRecorder = OpenTelemetryCoreRecorder.CreateParentActivity(operationName);
}
#endif
// Safety check as diagnostic logs should not break the code.
if (Activity.Current?.TraceId != null)
{
// This id would be useful to trace calls at backend services when distributed tracing feature is available there.
trace.AddDatum("DistributedTraceId", Activity.Current.TraceId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -47,9 +46,9 @@ public async Task ClientConfigTest()
Assert.IsNotNull(response.Diagnostics);
ITrace trace = ((CosmosTraceDiagnostics)response.Diagnostics).Value;
#if PREVIEW
Assert.AreEqual(trace.Data.Count, 2, string.Join(",", trace.Data.Select(a => $"{a.Key}: {a.Value}"))); // Distributed Tracing Id
Assert.AreEqual(actual: trace.Data.Count, expected: 2, message: string.Join(",", trace.Data.Select(a => $"{a.Key}: {a.Value}"))); // Distributed Tracing Id
#else
Assert.AreEqual(trace.Data.Count, 1, string.Join(",", trace.Data.Select(a => $"{a.Key}: {a.Value}")));
Assert.AreEqual(actual: trace.Data.Count, expected: 1, message: string.Join(",", trace.Data.Select(a => $"{a.Key}: {a.Value}")));
#endif
ClientConfigurationTraceDatum clientConfigurationTraceDatum = (ClientConfigurationTraceDatum)trace.Data["Client Configuration"];
Assert.IsNotNull(clientConfigurationTraceDatum.UserAgentContainer.UserAgent);
Expand Down

0 comments on commit f25967a

Please sign in to comment.