feat(tracing): add span link support#330
Conversation
This comment has been minimized.
This comment has been minimized.
BenchmarksBenchmark execution time: 2026-07-22 11:46:56 Comparing candidate commit dbee998 in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 7 metrics, 0 unstable metrics.
|
cbb3ed8 to
86d189e
Compare
003399b to
28432fe
Compare
| namespace datadog::tracing { | ||
|
|
||
| // Convenience alias: the map type used for span link user attributes. | ||
| using SpanLinkAttributes = std::unordered_map<std::string, std::string>; |
There was a problem hiding this comment.
@xlamorlette-datadog I want the add_link API to be able to accept a map where the attribute values could be one of many types (see https://github.com/open-telemetry/opentelemetry-cpp/blob/4e20f690352ce6c2793efcb6448e51363a2cad18/api/include/opentelemetry/common/attribute_value.h). Is there any easy way to for us to build that forward compatability right now, or should we just tackle that when we get to the point that we can record attributes in general to have a variety of primitive types (rather than strings)?
There was a problem hiding this comment.
Since span_link.h is no more public, I suppose this is no more an issue.
There was a problem hiding this comment.
This is still an issue because the public span API for creating a span link exposes a std::unordered_map<std::string, std::string> as a parameter:
void add_link(const SpanContext& context, const SpanLinkAttributes& attributes = {});Is it possible for us to keep this API today and then later overload it with a more permissive map? I know you're on PTO right now so we might want to take the change now and then update this in a follow-up PR
xlamorlette-datadog
left a comment
There was a problem hiding this comment.
Here are some technical comments.
Please get approval from @zacharycmontoya who understands the functionality way much better than me.
| namespace datadog::tracing { | ||
|
|
||
| // Convenience alias: the map type used for span link user attributes. | ||
| using SpanLinkAttributes = std::unordered_map<std::string, std::string>; |
There was a problem hiding this comment.
Since span_link.h is no more public, I suppose this is no more an issue.
zacharycmontoya
left a comment
There was a problem hiding this comment.
LGTM. I have left some comments but non are blocking, just nice-to-haves like keeping all the add_link API changes in this PR and utilizing the API in the behavior extract PR. There was one outstanding question I had about the unordered_map parameter we are accepting because in the future it should be more permissive and allow different types for the values, but I think we can address that later.
SpanContext gains an explicit constructor instead of relying on default member initializers, and SpanLink now stores a SpanContext member instead of duplicating trace_id/span_id/tracestate/flags fields. Also introduces the W3CLinkContext type alias for TraceSegment::w3c_link_context's return type.
|
Thanks! I cherry picked most api changes from PROPAGATION_BEHAVIOR_EXTRACT (except a few changes in parametric test server which were tied with propagation behavior changes) and resolved your other comments ! |
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