Skip to content

Conversation

@jessefoster
Copy link

What was changed

Added a function which can extract Open Telemetry Span from Workflow Context.

Why?

I saw Datadog had this capability already, see #1711, and my project needs access to Open Telemetry spans.

Checklist

  1. How was this tested:
    I've confirmed the feature works within my codebase and added unit tests as well. I've run all automated testing as prescribed here

  2. Any doc updates needed?
    None that I'm aware of

@jessefoster jessefoster requested a review from a team as a code owner November 21, 2025 21:56
@CLAassistant
Copy link

CLAassistant commented Nov 21, 2025

CLA assistant check
All committers have signed the CLA.

return trace.ContextWithSpan(ctx, span.(*tracerSpan).Span)
}

func SpanFromWorkflowContext(ctx workflow.Context) (trace.Span, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a godoc to this function explaining the functionality

Copy link
Author

Choose a reason for hiding this comment

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

Sure, godoc added


// SpanFromWorkflowContext extracts an OpenTelemetry span from the given
// workflow context. If no span is found, a no-op span is returned.
func SpanFromWorkflowContext(ctx workflow.Context) (trace.Span, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

Why return a bool that is always true?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this look like a bug


// SpanFromWorkflowContext extracts an OpenTelemetry span from the given
// workflow context. If no span is found, a no-op span is returned.
func SpanFromWorkflowContext(ctx workflow.Context) (trace.Span, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

May need to be clarified in the godoc that this is unsafe/non-deterministic because it can technically return different values when replaying vs not

Copy link
Author

Choose a reason for hiding this comment

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

So you'd like a comment warning people they should only use the Span data for observability needs? That's generally the assumption with observability tools, but I can make it explicit.


// SpanFromWorkflowContext extracts an OpenTelemetry span from the given
// workflow context. If no span is found, a no-op span is returned.
func SpanFromWorkflowContext(ctx workflow.Context) (trace.Span, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if SpanContextFromWorkflowContext is needed/better

Copy link
Author

Choose a reason for hiding this comment

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

We haven't had any need to use SpanContext, but it is another option. The Datadog interceptor only provides Span as well so I followed it's example since it's already in the codebase.

}

// Fallback to OpenTelemetry span extraction behavior
return trace.SpanFromContext(nil), true
Copy link
Contributor

Choose a reason for hiding this comment

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

This should return false

Copy link
Author

Choose a reason for hiding this comment

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

Yeah sorry about that, copy/paste mistake as I had to recreate file and run tests on another box. Not allowed to push directly from corporate laptop.

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.

4 participants