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

Adding trace.get_tracer #430

Merged

Conversation

toumorokoshi
Copy link
Member

As a convenience method to retrieve a tracer, introducing trace.get_tracer.

Overall I think this removes an extra element that is strongly implied.

@toumorokoshi toumorokoshi requested a review from a team February 18, 2020 22:20
Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

LGTM, I agree this is a better API.

opentelemetry-api/tests/trace/test_globals.py Outdated Show resolved Hide resolved
opentelemetry-api/tests/trace/test_globals.py Outdated Show resolved Hide resolved
toumorokoshi and others added 6 commits February 18, 2020 19:39
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 trace_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 <libc@google.com>
Co-Authored-By: Chris Kleinknecht <libc@google.com>
@codecov-io
Copy link

codecov-io commented Feb 19, 2020

Codecov Report

Merging #430 into master will increase coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #430      +/-   ##
==========================================
+ Coverage   88.19%   88.27%   +0.07%     
==========================================
  Files          41       41              
  Lines        2042     2047       +5     
  Branches      234      234              
==========================================
+ Hits         1801     1807       +6     
  Misses        170      170              
+ Partials       71       70       -1
Impacted Files Coverage Δ
...src/opentelemetry/ext/opentracing_shim/__init__.py 95.93% <ø> (ø) ⬆️
...ry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py 68.18% <100%> (ø) ⬆️
...-ext-flask/src/opentelemetry/ext/flask/__init__.py 88.88% <100%> (ø) ⬆️
...app/src/opentelemetry_example_app/flask_example.py 100% <100%> (ø) ⬆️
...ntelemetry-api/src/opentelemetry/trace/__init__.py 85.62% <100%> (+1.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 120ae29...b4ec34e. Read the comment docs.

Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

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

I agree this simplifies the API.

"""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.assertEqual(from_global_api, from_tracer_api)

Choose a reason for hiding this comment

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

assertIs?

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.

Thanks for making this change! 👍

@@ -663,6 +679,10 @@ def tracer_source() -> TracerSource:
except TypeError:
Copy link
Member

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?

Copy link
Contributor

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

Copy link
Member Author

@toumorokoshi toumorokoshi Feb 19, 2020

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).

@toumorokoshi toumorokoshi merged commit 972e2ab into open-telemetry:master Feb 19, 2020
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
closes open-telemetry#429

Signed-off-by: Olivier Albertini <olivier.albertini@montreal.ca>
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.

6 participants