Skip to content

Add coding examples for context #1165

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

Merged
merged 4 commits into from
Oct 22, 2020

Conversation

ahlaw
Copy link
Contributor

@ahlaw ahlaw commented Sep 25, 2020

Description

This PR adds coding samples in the documentation highlighting context behaviour.

Fixes #1140

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • Verified examples could be run on Python 3.5

Checklist:

  • Followed the style guidelines of this project
  • Documentation has been updated

@ahlaw ahlaw requested a review from a team September 25, 2020 16:47
@ahlaw ahlaw marked this pull request as draft September 25, 2020 16:47
@ahlaw ahlaw marked this pull request as ready for review September 25, 2020 18:29
@lzchen lzchen self-assigned this Oct 1, 2020
@codeboten codeboten self-assigned this Oct 8, 2020


async def main():
span = tracer.start_span(name="span", parent=None)
Copy link
Contributor

Choose a reason for hiding this comment

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

The parent is no longer a valid parameter here as of #1146, the parent is always passed in via the context

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

I think the examples are really close, just some changes due to #1146

with tracer.start_as_current_span(name="root span", parent=None) as root_span:
parent_ctx = baggage.set_baggage("context", "parent")
with tracer.start_as_current_span(
name="child span", parent=root_span
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name="child span", parent=root_span
name="child span", context=parent_ctx

from opentelemetry import trace

tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span(name="root span", parent=None) as root_span:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
with tracer.start_as_current_span(name="root span", parent=None) as root_span:
with tracer.start_as_current_span(name="root span", context=None) as root_span:

tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span(name="root span", parent=None) as root_span:
parent_ctx = baggage.set_baggage("context", "parent")
with tracer.start_as_current_span(name="child span", parent=root_span) as child_span:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above here, you'll want to pass in the context, rather than the span

@ahlaw ahlaw force-pushed the 1140-span-coding-samples branch from eb3a27c to 997f88d Compare October 21, 2020 07:18
@ahlaw ahlaw requested a review from codeboten October 21, 2020 07:40
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Thanks for the update!

@codeboten
Copy link
Contributor

The branch will need to be updated before merging.

@codeboten codeboten merged commit 51ed457 into open-telemetry:master Oct 22, 2020
@ahlaw ahlaw deleted the 1140-span-coding-samples branch October 22, 2020 17:09
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
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.

Create coding samples for span outlining context behaviour
3 participants