Skip to content

[SDK] Skip empty span links - #4772

Open
hidingmyname wants to merge 2 commits into
open-telemetry:mainfrom
hidingmyname:sdk-skip-empty-span-links-4749
Open

hidingmyname wants to merge 2 commits into
open-telemetry:mainfrom
hidingmyname:sdk-skip-empty-span-links-4749

Conversation

@hidingmyname

Copy link
Copy Markdown

Fixes #4749

Changes

A span link whose span context is invalid and which has no attributes and no
trace state carries no information. The SDK recorded such links anyway, so an
empty link could take a slot under link_count_limit and push out a real one
(with link_count_limit = 1 and links {empty, valid}, the empty link was
kept and the valid one dropped).

Span now skips these links in all three places links are recorded: links
passed at span creation, and AddLink / AddLinks (ABI v2). An invalid
context that still has attributes or a non-empty trace state is kept, as
before.

This is the same rule used by the Go (recordingSpan.AddLink), Java
(SdkSpan.addLink) and Python (_is_valid_link) SDKs.

Tests: new Tracer.SpanSkipsEmptyLinks in sdk/test/trace/tracer_test.cc:

  • link_count_limit = 1, links {empty, valid}: the valid link is recorded
    and 0 links are dropped.
  • An invalid context with a trace state, or with attributes, is still recorded.
  • ABI v2: AddLink / AddLinks with an empty link record nothing, and a
    following valid link is kept with 0 dropped.

Without the change in span.cc the new test fails (the empty link is
recorded and the valid one dropped), under both ABI v1 and ABI v2 (including
the AddLink / AddLinks case); with it, it passes.

Results (CMake, Debug, GCC 15.3, clang-format 18):

  • ABI v1: all trace SDK tests in sdk/test/trace pass (174/174 via ctest;
    tracer_test 45/45).
  • ABI v2 (WITH_ABI_VERSION_2=ON): tracer_test 48/48 pass, including
    SpanSkipsEmptyLinks with the AddLink / AddLinks cases and the existing
    SpanAddLinkAbiv2, SpanAddLinksAbiv2, SpanMixLinksAbiv2.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@hidingmyname
hidingmyname requested a review from a team as a code owner November 8, 2026 01:56
A link with an invalid span context, no attributes and no trace state carries
no information. Skip it when links are passed at span creation and in
AddLink/AddLinks (ABI v2), so it no longer takes a slot under link_count_limit.
This matches the Go, Java and Python SDKs.

Fixes open-telemetry#4749
@hidingmyname
hidingmyname force-pushed the sdk-skip-empty-span-links-4749 branch from d6198fc to d94021e Compare November 8, 2026 01:56

@mateenali66 mateenali66 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for the fix.

Under ABI v2, SpanSkipsEmptyLinks fails with the filter removed from any of the three call sites, or with either clause of IsEmptyLink dropped.

The rule matches the spec text on links with an empty TraceId or SpanId.

@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.62%. Comparing base (d05c6a8) to head (d94021e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4772      +/-   ##
==========================================
+ Coverage   86.61%   86.62%   +0.02%     
==========================================
  Files         530      530              
  Lines       21169    21176       +7     
==========================================
+ Hits        18333    18342       +9     
+ Misses       2836     2834       -2     
Files with missing lines Coverage Δ
sdk/src/trace/span.cc 95.20% <100.00%> (+0.29%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Resolve the include-what-you-use diagnostics for the empty-link fix.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK: skip completely empty span links (invalid SpanContext, no attributes, no TraceState) consistently in StartSpan / AddLink / AddLinks

2 participants