-
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
Use OPEN_SPANS
and custom record_exception
logic for all spans
#696
Conversation
OPEN_SPANS
and custom record_exception
logic for all spans
6f48eea
to
cc0e3ea
Compare
Deploying logfire-docs with Cloudflare Pages
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #696 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 137 137
Lines 11008 11008
Branches 1537 1537
=========================================
Hits 11008 11008 ☔ View full report in Codecov by Sentry. |
class _MaybeDeterministicTimestampSpan(trace_api.Span, ReadableSpan): | ||
class _LogfireWrappedSpan(trace_api.Span, ReadableSpan): |
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.
Rename makes sense 👍🏻
Should we make it a __slots__
data class (we should do it for all of them), using dynamic kwargs for python < 3.10, etc.? Can we another PR
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'd rather wait until we finish the refactoring to make it a __slots__
dataclass, just in case. But I think that makes sense once things are stable, maybe it would be fine to do it now I'd just rather not be thinking about it yet. Can change it now if you insist though.
logfire/_internal/tracer.py
Outdated
@@ -101,13 +115,17 @@ def force_flush(self, timeout_millis: int = 30000) -> bool: | |||
|
|||
|
|||
@dataclass |
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.
slots comment applies here
I'm working toward splitting
LogfireSpan
into a dedicated context manager, and a subclass ofReadableSpan
.This PR makes some of the changes we want to make along the way. In particular:
_ProxyTracer
are tracked inOPEN_SPANS
, and therefore should get properly closed on exit (even if created in generators, etc.), not just LogfireSpansrecord_exception
for all spans created by the logfire_ProxyTracer
_record_exception
and_set_exception_status
totracer
to prevent circular imports. They are now used in multiple modules, so I removed the leading_
, but they are only used in_internal
modules so I think that's okay._MaybeDeterministicTimestampSpan
to do theOPEN_SPANS
manipulation and overriderecord_exception
, since we were always returning spans wrapped with that class from_ProxyTracer.start_span
. Given its expanded usage, I also renamed that class to_LogfireWrappedSpan
. Given there are now behaviors we want to always override, I think we are paying less marginal overhead for setting the timestamp deterministically, so I think it's fine to rename the class and not even aspire to only use it when modifying the timestamp generation logic.user_attributes
toprepare_otlp_attributes
— this seems like a better name to me, and I found myself wanting to useuser_attributes
during my attempts to do more of the downstream refactors we've discussed, so I just figured it made sense to change that here.LogfireSpan.end()
compatible withtrace_api.Span
(required no other changes), since I think we may eventually want to rework things soLogfireSpan
is returned by_ProxyTracer.start_span
. Even if we don't, I think it's a fine change.I believe this PR has no user-facing API changes.