-
Notifications
You must be signed in to change notification settings - Fork 87
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
Improve Span Links API #726
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #726 +/- ##
===========================================
- Coverage 100.00% 99.93% -0.07%
===========================================
Files 139 140 +1
Lines 11206 11263 +57
Branches 1572 1578 +6
===========================================
+ Hits 11206 11256 +50
- Misses 0 5 +5
- Partials 0 2 +2 ☔ View full report in Codecov by Sentry. |
... | ||
|
||
# later on in another thread, process or service | ||
link = build_span_link(logfire_context) |
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.
Why wouldn't the user use with attach_context
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.
If it's attached, then it doesn't make sense to add a span link, does it?
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.
Right, I'm questioning adding (and recommending) build_span_link
. In this situation it seems more sensible to use a parent-child relationship instead of a span link.
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 mean, if I change the comment to "later on a task queue", would that be better? Or what you suggest instead?
By the way, I'm not sure build_span_link
is the best API for this, if we build_span_context
also works. I don't care which if the span(..., _links=[...])
accepts one of them.
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 mean, if I change the comment to "later on a task queue", would that be better?
No because regular distributed tracing still seems better.
Or what you suggest instead?
I honestly don't know when span links are useful in general. I suppose in your bigger example there's already a parent process_message
. If we assume that for whatever reason we really want to keep that as the parent, then we have to use a link. But then the docs should clarify that so that users only use links when it makes sense.
By the way, I'm not sure
build_span_link
is the best API for this, if webuild_span_context
also works. I don't care which if thespan(..., _links=[...])
accepts one of them.
I like that idea. Maybe name it get_span_context
.
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.
No because regular distributed tracing still seems better.
You disagree with open-telemetry/opentelemetry-python-contrib#3002 ?
I honestly don't know when span links are useful in general.
Besides Airflow, I'm not sure who uses them... But I feel they are supposed to be useful when you "trigger" something e.g. you have an endpoint, and you trigger a veryyyy long task somewhere else - you want to be able to close the span from the endpoint, and have a link to this very long task.
I like that idea. Maybe name it get_span_context.
👍
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.
No because regular distributed tracing still seems better.
You disagree with open-telemetry/opentelemetry-python-contrib#3002 ?
Overall, yes. What made you post that?
I honestly don't know when span links are useful in general.
Besides Airflow, I'm not sure who uses them... But I feel they are supposed to be useful when you "trigger" something e.g. you have an endpoint, and you trigger a veryyyy long task somewhere else - you want to be able to close the span from the endpoint,
The endpoint span will still be closed. It'll just have children that starts after it ends, which feels weird but should be harmless.
and have a link to this very long task.
The endpoint span won't have a link to the task span, only the other way around. Someone looking at the endpoint span has no easy way to find the task span.
Deploying logfire-docs with Cloudflare Pages
|
... | ||
|
||
# later on in another thread, process or service | ||
link = build_span_link(logfire_context) |
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 mean, if I change the comment to "later on a task queue", would that be better?
No because regular distributed tracing still seems better.
Or what you suggest instead?
I honestly don't know when span links are useful in general. I suppose in your bigger example there's already a parent process_message
. If we assume that for whatever reason we really want to keep that as the parent, then we have to use a link. But then the docs should clarify that so that users only use links when it makes sense.
By the way, I'm not sure
build_span_link
is the best API for this, if webuild_span_context
also works. I don't care which if thespan(..., _links=[...])
accepts one of them.
I like that idea. Maybe name it get_span_context
.
``` | ||
""" | ||
context = propagate.extract(carrier=carrier) | ||
span = cast(Span, next(iter(context.values()))) |
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.
The context can contain multiple values, e.g. baggage.
|
||
# later on in another thread, process or service | ||
link = build_span_link(logfire_context) | ||
with logfire.span('process_data', _links=[link]): |
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.
with logfire.span('process_data', _links=[link]): | |
with logfire.span('outer span'): | |
# can't use attach_context because we want to keep outer span as the parent | |
with logfire.span('process_data', _links=[link]): |
We didn't achieve consensus on span links. There's too much subjectivity involved here. One conclusion we got is that: we can have the |
Currently, it's not very ergonomic to create a span link.
Let's assume we have 2 services:
Main Service
And...
Service A
As you see, in the code, we set the headers with
logfire.propagate.get_context()
, and then on the subscriber, we need to run:We can for sure improve this. Either by passing
SpanContext
to_links
, or aLink
.This PR proposes creating:
logfire.propagate.build_span_link
: Creates a span link from aContextCarrier
, so it makes easier to use the propagate API we created. But... We can also build aspan_context
, instead ofLink
itself. It may be a bit more useful. I'm open to rework this.Link
andSpanContext
to the_links
parameter.I need to add tests here. I've first implemented this to bring back the discussion.