-
Notifications
You must be signed in to change notification settings - Fork 697
Adding trace.get_tracer #430
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
toumorokoshi
merged 7 commits into
open-telemetry:master
from
toumorokoshi:feature/get-tracer-root
Feb 19, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9695c86
Adding trace.get_tracer convenience function
toumorokoshi 5f2b4d7
Adding tests for trace.get_tracer
toumorokoshi 26a7fc1
Update opentelemetry-api/tests/trace/test_globals.py
toumorokoshi 634426a
Update opentelemetry-api/tests/trace/test_globals.py
toumorokoshi 182f241
fixing syntax after taking suggestions
toumorokoshi b4ec34e
fixing lint errors
toumorokoshi 252892f
switching assertEquals to assertIs
toumorokoshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import importlib | ||
import unittest | ||
|
||
from opentelemetry import trace | ||
|
||
|
||
class TestGlobals(unittest.TestCase): | ||
def setUp(self): | ||
importlib.reload(trace) | ||
|
||
# this class has to be declared after the importlib | ||
# reload, or else it will inherit from an old | ||
# TracerSource, rather than the new TraceSource ABC. | ||
# created from reload. | ||
|
||
static_tracer = trace.DefaultTracer() | ||
|
||
class DummyTracerSource(trace.TracerSource): | ||
"""TraceSource used for testing""" | ||
|
||
def get_tracer( | ||
self, | ||
instrumenting_module_name: str, | ||
instrumenting_library_version: str = "", | ||
) -> trace.Tracer: | ||
# pylint:disable=no-self-use,unused-argument | ||
return static_tracer | ||
|
||
trace.set_preferred_tracer_source_implementation( | ||
lambda _: DummyTracerSource() | ||
) | ||
|
||
@staticmethod | ||
def tearDown() -> None: | ||
importlib.reload(trace) | ||
|
||
def test_get_tracer(self): | ||
"""trace.get_tracer should proxy to the global tracer source.""" | ||
from_global_api = trace.get_tracer("foo") | ||
from_tracer_api = trace.tracer_source().get_tracer("foo") | ||
self.assertIs(from_global_api, from_tracer_api) |
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.
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.
Why do we even catch TypeErrors (and only TypeErrors) here?
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.
To catch exceptions when instantiating an abstract base class
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.
Thoughts on catching any exception here? the reason I added this was because I ran into behavior where I wasn't overriding the default tracer, and found it's because I had a bug in my unit test (caused by importllib.reload recreating all instances).
I feel like I'd want more feedback, but maybe that's already handled by the lack of an exception handler (error will just bubble up).