Skip to content

feat(tracing): add span link support#330

Open
MilanGarnier wants to merge 16 commits into
mainfrom
milan.garnier/span-links-support
Open

feat(tracing): add span link support#330
MilanGarnier wants to merge 16 commits into
mainfrom
milan.garnier/span-links-support

Conversation

@MilanGarnier

@MilanGarnier MilanGarnier commented Jun 30, 2026

Copy link
Copy Markdown

Description

Adds OpenTelemetry-style span links to dd-trace-cpp.

  • ExtractedContext struct (include/datadog/extracted_context.h)
  • SpanLink struct (include/datadog/span_link.h): 128-bit trace_id, span_id, optional tracestate, string attributes, optional flags.
  • msgpack serialization (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_high only when non-zero, span_id, attributes only when non-empty, tracestate only when non-empty, flags with high bit set when present).
  • SpanData::span_links (src/datadog/span_data.h/.cpp): std::vector<SpanLink> field; the span encoder emits a span_links array only when non-empty (matches omitempty behaviour 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.
  • Parametric endpoint 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_EXTRACT config (planned).

Additional Notes

@datadog-datadog-prod-us1-2

This comment has been minimized.

@pr-commenter

pr-commenter Bot commented Jun 30, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-06 11:07:17

Comparing candidate commit 5311345 in PR branch milan.garnier/span-links-support with baseline commit d7ea3a8 in branch main.

Found 2 performance improvements and 3 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:BM_HexPadded_uint64/NoPadding

  • 🟥 execution_time [+2.433ns; +2.497ns] or [+4.529%; +4.649%]

scenario:BM_HexPadded_uint64/WorstCasePadding

  • 🟥 execution_time [+1.656ns; +1.758ns] or [+3.368%; +3.576%]

scenario:BM_Hex_uint64

  • 🟩 execution_time [-0.991ns; -0.966ns] or [-4.186%; -4.080%]

scenario:BM_TraceID_ParseHex/128bit

  • 🟩 execution_time [-3.988ns; -3.969ns] or [-3.171%; -3.156%]

scenario:BM_TraceTinyCCSource

  • 🟥 execution_time [+2.426ms; +2.656ms] or [+3.260%; +3.569%]

@MilanGarnier MilanGarnier changed the title feat(tracing): add support for span links feat(tracing): add span link support Jun 30, 2026
@MilanGarnier MilanGarnier marked this pull request as draft June 30, 2026 15:25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread include/datadog/span.h
Comment thread src/datadog/span_data.cpp

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread include/datadog/span.h Outdated
Comment thread test/system-tests/request_handler.cpp Outdated

@xlamorlette-datadog xlamorlette-datadog left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please rather use nested namespace syntax

Comment thread src/datadog/span.cpp
// 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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, clean code: please use meaningful variable names (this is not Go ;-) )

Comment thread src/datadog/span_data.cpp
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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we name these magic numbers?

Comment thread src/datadog/span_data.cpp
});
if (!result) return result;
}
// clang-format on

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opt: to be checked (I could do it): why do we need this clang-format exclusion?

@MilanGarnier MilanGarnier Jul 6, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/datadog/span_link.cpp
namespace datadog {
namespace tracing {

Expected<void> msgpack_encode(std::string& destination, const SpanLink& link) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, clean code: please try to split this big function

res.status = 200;
}

void RequestHandler::on_add_link(const httplib::Request& req,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, clean code: please try to split this big function

};
const auto upstream_id = span->parent_id().value_or(0);

StoredLinkContext stored;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, clean code: please try to extract this additional part to avoid make this function, which is already too big, grow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants