-
Notifications
You must be signed in to change notification settings - Fork 624
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
Conversation
583e618
to
77228e6
Compare
a7d8236
to
096d69d
Compare
if span.is_recording(): | ||
span.set_status(Status(StatusCode.ERROR, str(ex))) | ||
raise ex | ||
return await query_method(*args, **kwargs) |
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.
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 |
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.
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") |
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.
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.
096d69d
to
4c63129
Compare
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.
nice, this cleans up the code quite a bit
Description
Replaces
Tracer.use_span()
withopentelemetry.trace.use_span()
.Fixes open-telemetry/opentelemetry-python#1630
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.