feat(otel): add otel tracing for standalone activities.#647
Conversation
4218658 to
6b5fa88
Compare
|
|
||
| // Setup provider | ||
| using var tracerProvider = global::OpenTelemetry.Sdk.CreateTracerProviderBuilder(). | ||
| using var _ = global::OpenTelemetry.Sdk.CreateTracerProviderBuilder(). |
There was a problem hiding this comment.
Took me a second to realize that tracerProvider was not actually being used we were just using using for lifetime management. Swapped to discard variable instead which preserves lifetime management but better signals intent.
| $"StartActivity:{input.Activity}", | ||
| kind: ActivityKind.Client, | ||
| parentContext: default, | ||
| tags: input.Options.Id is string id ? root.CreateStandaloneActivityTags(id) : null)) |
There was a problem hiding this comment.
input.Options.Id is optional because it uses the shared StartActivityInput. AFAICT, it will never be null for standalone activities.
There was a problem hiding this comment.
It shouldn't be null (and is documented that it is required), but customers can still pass null. Given the current type declaration, you are doing the right thing here. The validation of the value is done within the innermost interceptor, which hasn't been called at this point.
…onsistency across SDKs. update tests.
0e7a4f4 to
6c3d6a2
Compare
| /// </summary> | ||
| /// <param name="activityId">Standalone activity ID.</param> | ||
| /// <returns>Tags.</returns> | ||
| protected virtual IEnumerable<KeyValuePair<string, object?>> CreateStandaloneActivityTags( |
There was a problem hiding this comment.
I could just inline this logic now that start_activity is the only event we are adding tracing to.
There was a problem hiding this comment.
I think it's fine to leave here as-is. There's precedent for this pattern.
| var spans = await WithTracingWorkerAsync(async (client, _) => | ||
| { | ||
| await client.StartActivityAsync( | ||
| "StandaloneActivity", |
There was a problem hiding this comment.
nit: choose a different name so we don't accidentally happen to match the well known primitive name
…lict with existing spans in the testing framework.
What was changed
Implemented OTel interceptor methods for client standalone activities:
Why?
Users now have OTel tracing info available for standalone activities.
Checklist
dotnet test