Parent is now always passed in via Context, intead of Span or SpanContext#1146
Parent is now always passed in via Context, intead of Span or SpanContext#1146codeboten merged 25 commits intoopen-telemetry:masterfrom
Conversation
toumorokoshi
left a comment
There was a problem hiding this comment.
one non-blocking comment on variable naming. I think it's probably one that needs to be addressed, but don't want to stop progress if I don't catch up to this PR.
| parent_context, trace_api.SpanContext | ||
| ): | ||
| raise TypeError("parent must be a Span, SpanContext or None.") | ||
| raise TypeError("parent_context must be a SpanContext or None.") |
There was a problem hiding this comment.
I guess this type validation is still valuable. But practically speaking, this would only be an issue if someone directly manipulates the context, and doesn't use the API functions.
Is that a common enough case to even catch here?
Alternatively I suppose this is cheap enough.
| self, | ||
| name: str, | ||
| parent: ParentSpan = CURRENT_SPAN, | ||
| parent: typing.Optional[Context] = None, |
There was a problem hiding this comment.
I'm wondering if the variable is worth renaming. "parent" was vague to begin with, and if you look at any descriptions of how tracing works, one would immediately think "parent" refers to the span (since you specifically call the span a child of the parent span).
This would also be useful to rename since new API users will get exceptions when their existing code passes an argument as parent. Rather than get a new slightly confusing error ("why is the API now rejecting this previously valid value?"), they will get an argument not supported error, and look up the docs to see the variable changed.
parent_context is the first thing that comes to mind, but I worry a user would get it confused with the parent SpanContext.
There was a problem hiding this comment.
@toumorokoshi yeah I had a similar thought around the name. Looking at some of the other implementations, it appears parent and parent_context are the current names used. I'm happy to change it to parent_context as it's at least a bit more meaningful than parent. The alternative i can think of would be to just call it context
There was a problem hiding this comment.
I'd say context is the better name. A Context object passed in this argument may or may not contain a parent Span, making the name parent_context less accurate and context_with_or_without_the_parent_span is a bit long.
There was a problem hiding this comment.
Thanks for the feedback, went with context.
| parent_context = parent | ||
| if isinstance(parent_context, trace_api.Span): | ||
| parent_context = parent.get_context() | ||
| parent_context = trace_api.get_current_span(parent).get_context() |
There was a problem hiding this comment.
Now that there is the concept of a Context being passed into span start, I'm wondering if it is valuable to rename span.get_context() to span.get_span_context() to avoid confusion. I know that the Context isn't actually a PART of Span, it probably is only here (during start and use) that it would be confusing. Thoughts?
There was a problem hiding this comment.
And maybe even renaming the variable from parent_context to parent_span_context.
There was a problem hiding this comment.
I would +1 on "get_span_context", although with open-telemetry/opentelemetry-specification#1033 that might not even be necessary.
There was a problem hiding this comment.
I renamed get_context to get_span_context and parent_context to parent_span_context where it made sense. I tested the water with renaming context in the Span to span_context and it turned out to be pretty messy. Not sure if it's worth the rename on that one. Thoughts @lzchen & @toumorokoshi?
There was a problem hiding this comment.
I think that's fine, I don't know if I have a strong opinion on the attribute name on the span.
And I'm completely comfortable with taking these PRs piecemeal too.
ocelotl
left a comment
There was a problem hiding this comment.
Just some minor comments
| self, | ||
| name: str, | ||
| parent: ParentSpan = CURRENT_SPAN, | ||
| parent: typing.Optional[Context] = None, |
There was a problem hiding this comment.
I'd say context is the better name. A Context object passed in this argument may or may not contain a parent Span, making the name parent_context less accurate and context_with_or_without_the_parent_span is a bit long.
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
Description
As per the spec change open-telemetry/opentelemetry-specification#875, the parent must always be passed via a Context.
Fixes #1139
Type of change
Please delete options that are not relevant.
Checklist: