Replaced Tracer.use_span() with opentelemetry.trace.use_span()#364
Merged
codeboten merged 1 commit intoopen-telemetry:mainfrom Mar 8, 2021
Merged
Replaced Tracer.use_span() with opentelemetry.trace.use_span()#364codeboten merged 1 commit intoopen-telemetry:mainfrom
codeboten merged 1 commit intoopen-telemetry:mainfrom
Conversation
583e618 to
77228e6
Compare
a7d8236 to
096d69d
Compare
owais
commented
Mar 4, 2021
| if span.is_recording(): | ||
| span.set_status(Status(StatusCode.ERROR, str(ex))) | ||
| raise ex | ||
| return await query_method(*args, **kwargs) |
Contributor
Author
There was a problem hiding this comment.
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 |
Contributor
Author
There was a problem hiding this comment.
pylint has false positives when using a generator as context manager so ignoring rule.
| span.status.status_code, trace_api.status.StatusCode.ERROR | ||
| ) | ||
| self.assertEqual(span.status.description, "Test Exception") | ||
| self.assertEqual(span.status.description, "Exception: Test Exception") |
Contributor
Author
There was a problem hiding this comment.
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.
11 tasks
096d69d to
4c63129
Compare
codeboten
approved these changes
Mar 6, 2021
Contributor
codeboten
left a comment
There was a problem hiding this comment.
nice, this cleans up the code quite a bit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.