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

Replaced Tracer.use_span() with opentelemetry.trace.use_span() #364

Merged
merged 1 commit into from
Mar 8, 2021

Conversation

owais
Copy link
Contributor

@owais owais commented Mar 4, 2021

Description

Replaces Tracer.use_span() with opentelemetry.trace.use_span().

Fixes open-telemetry/opentelemetry-python#1630

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Updated existing tests

Does This PR Require a Core Repo Change?

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

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

@owais owais force-pushed the update-use_span-usage branch from 583e618 to 77228e6 Compare March 4, 2021 13:57
@owais owais changed the title Replaced Tracer.use_span() with opentelemetry.trace.use_span() WIP: Replaced Tracer.use_span() with opentelemetry.trace.use_span() Mar 4, 2021
@owais owais marked this pull request as ready for review March 4, 2021 13:58
@owais owais requested review from a team, toumorokoshi and hectorhdzg and removed request for a team March 4, 2021 13:58
@owais owais force-pushed the update-use_span-usage branch 7 times, most recently from a7d8236 to 096d69d Compare March 4, 2021 16:33
@owais owais changed the title WIP: Replaced Tracer.use_span() with opentelemetry.trace.use_span() Replaced Tracer.use_span() with opentelemetry.trace.use_span() Mar 4, 2021
if span.is_recording():
span.set_status(Status(StatusCode.ERROR, str(ex)))
raise ex
return await query_method(*args, **kwargs)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The context manager above (start_as_current_span) handles exceptions and records them as status already so this was completely unnecessary/redundant. Some similar changes below.

activation = self._tracer.use_span(span, end_on_exit=True)
activation.__enter__()
activation = trace.use_span(span, end_on_exit=True)
activation.__enter__() # pylint: disable=E1101
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pylint has false positives when using a generator as context manager so ignoring rule.

@@ -322,7 +320,7 @@ def test_span_failed(self):
self.assertIs(
span.status.status_code, trace_api.status.StatusCode.ERROR
)
self.assertEqual(span.status.description, "Test Exception")
self.assertEqual(span.status.description, "Exception: Test Exception")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instrumentation was duplicating start_as_current_span's exception handling and not formatting the description properly. After removing the duplicate code, had to update the assertion to expect description formatted by the context manager. Similar changes below.

@owais owais force-pushed the update-use_span-usage branch from 096d69d to 4c63129 Compare March 4, 2021 21:45
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.

nice, this cleans up the code quite a bit

@codeboten codeboten merged commit f436514 into open-telemetry:main Mar 8, 2021
@owais owais deleted the update-use_span-usage branch March 8, 2021 19:43
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.

Move useSpan() out of Tracer
2 participants