Skip to content
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

Merged
merged 25 commits into from
Oct 8, 2020

Conversation

codeboten
Copy link
Contributor

@codeboten codeboten commented Sep 22, 2020

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.

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been updated
  • Documentation has been updated

@codeboten codeboten changed the title WIP: Parent is now always passed in via Context, intead of Span or SpanCon… WIP: Parent is now always passed in via Context, intead of Span or SpanContext Sep 22, 2020
@codeboten codeboten added the release:required-for-ga To be resolved before GA release label Sep 24, 2020
@codeboten codeboten self-assigned this Sep 24, 2020
@lzchen lzchen mentioned this pull request Sep 29, 2020
3 tasks
@codeboten codeboten changed the title WIP: Parent is now always passed in via Context, intead of Span or SpanContext Parent is now always passed in via Context, intead of Span or SpanContext Oct 2, 2020
@codeboten codeboten marked this pull request as ready for review October 2, 2020 04:57
@codeboten codeboten requested a review from a team October 2, 2020 04:57
Copy link
Member

@toumorokoshi toumorokoshi left a 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.")
Copy link
Member

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,
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Either sounds great!

Copy link
Contributor

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.

Copy link
Contributor Author

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

@lzchen lzchen Oct 6, 2020

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?

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor

@ocelotl ocelotl left a 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,
Copy link
Contributor

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.

opentelemetry-api/src/opentelemetry/trace/__init__.py Outdated Show resolved Hide resolved
opentelemetry-api/src/opentelemetry/trace/__init__.py Outdated Show resolved Hide resolved
@codeboten codeboten merged commit 0e852ea into open-telemetry:master Oct 8, 2020
@codeboten codeboten deleted the parent-context branch October 8, 2020 15:39
@codeboten codeboten mentioned this pull request Oct 14, 2020
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:required-for-ga To be resolved before GA release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spans's parent must be passed as Context instead of Span(Context)s
4 participants