Repository navigation
feat(tracing): Add span links - #8068
Conversation
Coverage Results 📊✅ 56441 passed | ⏭️ 2890 skipped | Total: 59331 | Pass Rate: 95.13% | Execution Time: 150m 54s 📊 Comparison with Base Branch
➖ Removed Tests (58)View removed tests
All tests are passing successfully. ✅ Patch coverage is 100.00% (31 of 31 changed executable lines covered; target 80%). Changed files with executable lines (2)
Coverage diff@@ Coverage Diff @@
## master #8068 +/-##
==========================================
- Coverage 90.31% 90.05% -0.26%
==========================================
Files 203 197 -6
Tracked lines 26866 21086 -5780
Branches 10030 7260 -2770
==========================================
- Hits 24262 18988 -5274
+ Misses 2604 2098 -506
+ Partials 1517 1236 -281Generated by Coverage Action |
sentrivana
left a comment
There was a problem hiding this comment.
Looks good, but please address comments before merging
| if "attributes" in link | ||
| else link | ||
| for link in item["links"] | ||
| ] |
There was a problem hiding this comment.
If there are no links, would we still send an empty links key? If so, we should delete it like we do for attributes on L186, to keep the payload as small as possible.
There was a problem hiding this comment.
No links isn't set when there aren't any; they are only set in Span._to_json() @ traces.py:577 when there's > 1 link to be sent.
| res["links"] = [ | ||
| { | ||
| **link, | ||
| "attributes": { | ||
| k: serialize_attribute(v) | ||
| for (k, v) in link["attributes"].items() | ||
| }, | ||
| } | ||
| if "attributes" in link | ||
| else link | ||
| for link in item["links"] | ||
| ] |
There was a problem hiding this comment.
Can we maybe unfurl this into statements instead of the one big list comprehension? Easier to parse that way
Description
Adds span links as is specified in the specs: a span can reference other spans, e.g. in other traces, without making them its parent.
sentry_sdk.start_span(..., links=[...]),span.add_link(link)andspan.add_links(links); with links being of the following format:{"trace_id", "span_id", "sampled"?, "attributes"?}linksNoOpSpanignores linksRelated docs update can be found here.
Why
An SQS/SNS consumer can receive a batch of records sent by several producers, each in its own trace. A span can only have one parent, so without links there's no way to connect the consumer each producer. With links the consumer span can point to each producer's trace.