-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add APIs for getting the current logfire span #675
base: main
Are you sure you want to change the base?
Conversation
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.
I think we should use the existing OTEL APIs
Deploying logfire-docs with Cloudflare Pages
|
3f2e6ee
to
17cfbc7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #675 +/- ##
===========================================
- Coverage 100.00% 99.91% -0.09%
===========================================
Files 137 138 +1
Lines 10750 10793 +43
Branches 1473 1475 +2
===========================================
+ Hits 10750 10784 +34
- Misses 0 7 +7
- Partials 0 2 +2 ☔ View full report in Codecov by Sentry. |
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.
I would suggest we add just current_logfire_span
, but perhaps for consistency it should be called get_current_logfire_span
?
Is there a noticeable memory or CPU overhead? I assume not, but we should perhaps do some basic checks.
Let's see what @alexmojaki says, but I'm strongly in favour of moving quickly, even if it's with an imperfect solution.
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.
are we sure this should be public.
@@ -21,6 +21,7 @@ | |||
from ._internal.main import Logfire, LogfireSpan | |||
from ._internal.scrubbing import ScrubbingOptions, ScrubMatch | |||
from ._internal.utils import suppress_instrumentation | |||
from .current_span import current_logfire_span, current_span |
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.
I think it could be confusing or cause weird side effects that the imported current_span
overrides the current_span
module.
Addresses #674
This is a proposed implementation for how we can make it possible to get access to the current
LogfireSpan
, for making use of the various methods/etc. on it that aren't on the result ofopentelemetry.trace.get_current_span()
when you don't have access to the value.The motivating use case for this is having access to methods of
LogfireSpan
inside functions instrumented with@logfire.instrument
. Right now, there is no way to get access to theLogfireSpan
, asopentelemetry.trace.get_current_span
doesn't return that. This PR makes it so thatlogfire.current_logfire_span()
returns theLogfireSpan
if the current otel span corresponds to aLogfireSpan
, and something API-compatible if it does not. (I also addedlogfire.current_span()
as a more easily discovered re-export ofopentelemetry.trace.get_current_span
, don't necessarily need to keep that.)Note that we've discussed making it so that when you call
opentelemetry.trace.get_current_span()
you get aLogfireSpan
back, but the naive approach to this would have the consequence that spans created by other instrumentations would also end up beingLogfireSpan
s, with the associated modified method behaviors/overhead/etc. This may be a good idea, but it's not immediately clear to me.The good news is that the implementation in this PR would be backwards compatible if we were to make that change, and most of the logic brought in in this PR would just get removed, just the
current_span
andcurrent_logfire_span
functions would remain.I haven't added any tests yet, mostly because I don't want to put in the effort if the approach is going to be rejected.