feat(tracing): add span link support#330
Conversation
This comment has been minimized.
This comment has been minimized.
BenchmarksBenchmark execution time: 2026-07-06 11:07:17 Comparing candidate commit 5311345 in PR branch Found 2 performance improvements and 3 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.
|
cbb3ed8 to
86d189e
Compare
003399b to
28432fe
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a36ade09f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c2f121762
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
8492993 to
5c93eca
Compare
xlamorlette-datadog
left a comment
There was a problem hiding this comment.
This is only a first very light and superficial review, I should review in detail in a few days.
| #include "optional.h" | ||
| #include "trace_id.h" | ||
|
|
||
| namespace datadog { |
There was a problem hiding this comment.
nit: please rather use nested namespace syntax
| // Capture injected headers (tracestate, traceparent flags) into a map. | ||
| struct : DictWriter { | ||
| std::unordered_map<std::string, std::string> map; | ||
| void set(StringView k, StringView v) override { |
There was a problem hiding this comment.
nit, clean code: please use meaningful variable names (this is not Go ;-) )
| const bool has_links = !span.span_links.empty(); | ||
|
|
||
| // 12 always-present fields, plus span_links when there are any. | ||
| auto result = msgpack::pack_map(destination, has_links ? 13u : 12u); |
There was a problem hiding this comment.
nit: could we name these magic numbers?
| }); | ||
| if (!result) return result; | ||
| } | ||
| // clang-format on |
There was a problem hiding this comment.
opt: to be checked (I could do it): why do we need this clang-format exclusion?
There was a problem hiding this comment.
this was already present before and the reason is that msgpack::pack_map_suffix(...) was not properly formatted. I can totally remove the comments and stage the formatted version instead
| namespace datadog { | ||
| namespace tracing { | ||
|
|
||
| Expected<void> msgpack_encode(std::string& destination, const SpanLink& link) { |
There was a problem hiding this comment.
nit, clean code: please try to split this big function
| res.status = 200; | ||
| } | ||
|
|
||
| void RequestHandler::on_add_link(const httplib::Request& req, |
There was a problem hiding this comment.
nit, clean code: please try to split this big function
| }; | ||
| const auto upstream_id = span->parent_id().value_or(0); | ||
|
|
||
| StoredLinkContext stored; |
There was a problem hiding this comment.
nit, clean code: please try to extract this additional part to avoid make this function, which is already too big, grow
Description
Adds OpenTelemetry-style span links to dd-trace-cpp.
ExtractedContext struct(include/datadog/extracted_context.h)SpanLinkstruct (include/datadog/span_link.h): 128-bittrace_id,span_id, optionaltracestate, stringattributes, optionalflags.src/datadog/span_link.cpp): per-link map with the exact field names and omission rules used by dd-trace-go / dd-trace-py / dd-trace-rs (trace_id,trace_id_highonly when non-zero,span_id,attributesonly when non-empty,tracestateonly when non-empty,flagswith high bit set when present).SpanData::span_links(src/datadog/span_data.h/.cpp):std::vector<SpanLink>field; the span encoder emits aspan_linksarray only when non-empty (matchesomitemptybehaviour of other tracers).Span::add_link(const SpanLink&)(include/datadog/span.h,src/datadog/span.cpp): public API to attach a link to a live span.POST /trace/span/add_link(test/system-tests/): wires up the cross-language system-test client contract.Motivation
This feature is supported by all other tracers and is a dependency for future implementations, such as
DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACTconfig (planned).Additional Notes
test/test_span_link.cppandtest/test_span.cppexercise serialization and the public API end-to-end.Jira ticket: APMAPI-1941