-
Notifications
You must be signed in to change notification settings - Fork 272
Add SpanFromWorkflowContext function for OTel #2118
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
base: master
Are you sure you want to change the base?
Conversation
| return trace.ContextWithSpan(ctx, span.(*tracerSpan).Span) | ||
| } | ||
|
|
||
| func SpanFromWorkflowContext(ctx workflow.Context) (trace.Span, bool) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, godoc added
3f9e3d5 to
06ebaba
Compare
|
|
||
| // 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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return false
There was a problem hiding this comment.
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.
06ebaba to
8083b21
Compare
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
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
Any doc updates needed?
None that I'm aware of