-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's fairly common to need to retrieve tracers, and as such adding the additional tracer_source() call to every retrieval of a tracer can add to a lot of extra boilerplate at minimal semantic value. It would be uncommon for one to use multiple tracer_source objects, as typically one would want all tracers to be created and behave in a similar way (e.g. passed to the same span processor). Co-Authored-By: Chris Kleinknecht <[email protected]>
- Loading branch information
1 parent
5a0dae9
commit 972e2ab
Showing
15 changed files
with
75 additions
and
14 deletions.
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) |