-
Notifications
You must be signed in to change notification settings - Fork 553
Patch TracerProvider
if it already exists
#4455
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
Conversation
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## potel-base #4455 +/- ##
==============================================
- Coverage 84.80% 84.78% -0.02%
==============================================
Files 144 144
Lines 14728 14742 +14
Branches 2343 2346 +3
==============================================
+ Hits 12490 12499 +9
- Misses 1523 1525 +2
- Partials 715 718 +3
|
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.
just a question
there's also the case where someone adds a custom sampler but let's just ignore that for now, worst case we tell people to update their sampler to derive from sentry's sampler if they really want even more custom logic
for span_processor in existing_span_processors: | ||
if isinstance(span_processor, SentrySpanProcessor): | ||
break | ||
else: |
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.
lol til there is for else in python
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.
Yeah this is kinda obscure. I used to avoid it for that reason but I somewhat like it now
sentry_sdk/opentelemetry/tracing.py
Outdated
|
||
if _TRACER_PROVIDER is not None: | ||
logger.debug("[Tracing] Detected an existing TracerProvider, patching") | ||
tracer_provider = trace.get_tracer_provider() |
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.
is _TRACER_PROVIDER
above different than what get_tracer_provider
returns?
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.
Yes, there's some extra logic tied around get_tracer_provider
, see 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.
but that branch only runs when it's None, anyway doesn't matter that much
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.
Ah, got you now. Thought this was about potentially not using _TRACER_PROVIDER
at all and switching to get_tracer_provider
.
Yeah we can just use _TRACER_PROVIDER
on this line, the get_tracer_provider
call here is redundant. Will change.
We can also skip setting the sampler here and tell people to do it themselves. Arguably just overwriting it here silently is not great, but at the same time, we have so much important custom logic in the Sentry sampler that it kinda feels like it should be there from the get go to be able to use the whole thing meaningfully. |
No, the default experience is more important than custom use cases. JS exposes a |
If a `TracerProvider` already exists, patch it. `TracerProvider` is a singleton, so if we aren't the first ones setting it up, we need to use the existing one. In tests, reset `TracerProvider` after each test so that we start with a clean slate and it gets set up anew on init.
If a `TracerProvider` already exists, patch it. `TracerProvider` is a singleton, so if we aren't the first ones setting it up, we need to use the existing one. In tests, reset `TracerProvider` after each test so that we start with a clean slate and it gets set up anew on init.
If a
TracerProvider
already exists, patch it.TracerProvider
is a singleton, so if we aren't the first ones setting it up, we need to use the existing one.In tests, reset
TracerProvider
after each test so that we start with a clean slate and it gets set up anew on init.