Skip to content

feat(otel): add otel tracing for standalone activities.#647

Open
cconstable wants to merge 5 commits into
mainfrom
cc/standalone-activity-tracing
Open

feat(otel): add otel tracing for standalone activities.#647
cconstable wants to merge 5 commits into
mainfrom
cc/standalone-activity-tracing

Conversation

@cconstable
Copy link
Copy Markdown
Contributor

@cconstable cconstable commented Apr 22, 2026

What was changed

Implemented OTel interceptor methods for client standalone activities:

  • start_activity

Why?

Users now have OTel tracing info available for standalone activities.

Checklist

  1. Closes SDK-5175
  2. How was this tested: new tests + dotnet test
  3. Any docs updates needed? no

@cconstable cconstable marked this pull request as ready for review April 23, 2026 15:23
@cconstable cconstable requested a review from a team as a code owner April 23, 2026 15:23
@cconstable cconstable force-pushed the cc/standalone-activity-tracing branch from 4218658 to 6b5fa88 Compare April 23, 2026 15:25

// Setup provider
using var tracerProvider = global::OpenTelemetry.Sdk.CreateTracerProviderBuilder().
using var _ = global::OpenTelemetry.Sdk.CreateTracerProviderBuilder().
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input.Options.Id is optional because it uses the shared StartActivityInput. AFAICT, it will never be null for standalone activities.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cconstable cconstable force-pushed the cc/standalone-activity-tracing branch from 0e7a4f4 to 6c3d6a2 Compare May 11, 2026 16:47
/// </summary>
/// <param name="activityId">Standalone activity ID.</param>
/// <returns>Tags.</returns>
protected virtual IEnumerable<KeyValuePair<string, object?>> CreateStandaloneActivityTags(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could just inline this logic now that start_activity is the only event we are adding tracing to.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants