-
Notifications
You must be signed in to change notification settings - Fork 650
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
Parent is now always passed in via Context, intead of Span or SpanContext #1146
Conversation
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.
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.
|
||
if parent_context is not None and not isinstance( | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -228,7 +226,7 @@ class Tracer(abc.ABC): | |||
def start_span( | |||
self, | |||
name: str, | |||
parent: ParentSpan = CURRENT_SPAN, | |||
parent: typing.Optional[Context] = None, |
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'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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either sounds great!
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'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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And maybe even renaming the variable from parent_context
to parent_span_context
.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Just some minor comments
@@ -228,7 +226,7 @@ class Tracer(abc.ABC): | |||
def start_span( | |||
self, | |||
name: str, | |||
parent: ParentSpan = CURRENT_SPAN, | |||
parent: typing.Optional[Context] = None, |
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'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: