Skip to content

Record where a span's parent came from on DDSpanContext - #13452

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
matthew.li/span-context-parent-origin
Nov 16, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
matthew.li/span-context-parent-origin

Conversation

@mhlidd

@mhlidd mhlidd commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Every DDSpanContext now records where its parent came from, as a final parentOrigin byte with one of three values:

  • PARENT_ORIGIN_NONE: no parent span ID.
  • PARENT_ORIGIN_LOCAL: the parent is in-process.
  • PARENT_ORIGIN_REMOTE: the parent is an extracted context.

CoreTracer.buildSpanContext sets it from the resolved parent context, and DDSpanContext.getParentOrigin() exposes it. There is no behavior change: nothing reads it in production yet, and it is not serialized or tagged.

Motivation

The OTel SDK self-monitoring metrics otel.sdk.span.started and otel.sdk.span.live need the otel.span.parent.origin attribute (none / local / remote). Today the span keeps only parentId once it is built, so it can't tell an extracted parent from an in-process one. The hook that ends a span also needs the same origin that was recorded at start, so the origin has to live on the span context. This PR adds the field. The metrics PR that reads it follows separately.

Additional Notes

  • Classification. If parentSpanId == DDSpanId.ZERO the origin is NONE. Otherwise it is REMOTE when resolvedParentSpanContext.isRemote() and LOCAL when not. REMOTE therefore mirrors AgentSpanContext.isRemote().
    • ExtractedContext and TagContext report remote.
    • A TagContext with no trace, or a remote parent dropped under trace.propagation.behavior.extract=restart, ends up with no parent span ID, so it is NONE.
    • Spark parent contexts (DatabricksParentContext, OpenlineageParentContext, PredeterminedTraceIdContext) report isRemote() == false, so they classify as LOCAL.
  • Constructors. A new constructor takes parentOrigin. The previous primary constructor delegates to it and derives the origin from parentId alone (NONE or LOCAL), so the other 23 call sites, mostly tests and JMH benchmarks, are unchanged.
  • Memory. I checked with JOL (ClassLayout.parseClass(DDSpanContext.class), Temurin 25). DDSpanContext stays at 152 B with compressed oops, and at 248 B in JOL's simulated layout without compressed oops. The byte fills an existing 1-byte padding gap, and no reference field moves.
  • Alternative considered. Deriving the origin later as "local root span with a non-zero parent ID" needs no new field. It was rejected because it depends on the root span never changing between span start and end, and because it misclassifies non-extracted foreign parents.
  • Tests. Five new CoreSpanBuilderTest cases: root span, child of a local span, child of an extracted context, child of an empty TagContext, and a remote parent dropped on restart.

Contributor Checklist

Jira ticket: [PROJ-IDENT]

🤖 Generated with Claude Code

The span builder sets a final parentOrigin byte (none, local or remote)
from the resolved parent context, so later consumers such as the
otel.sdk.span.* self-monitoring metrics can tell extracted parents
from in-process ones after the parent context is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mhlidd mhlidd added type: feature Enhancements and improvements comp: core Tracer core tag: no release notes Changes to exclude from release notes tag: ai generated Largely based on code generated by an AI or LLM labels Nov 13, 2026
@mhlidd
mhlidd marked this pull request as ready for review November 13, 2026 20:15
@mhlidd
mhlidd requested a review from a team as a code owner November 13, 2026 20:15
@mhlidd
mhlidd requested review from jordan-wong and removed request for a team November 13, 2026 20:15
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T20:18:59.411153Z 09d07d7 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@mhlidd
mhlidd requested review from dougqh and mcculls November 13, 2026 20:16

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Parent-origin classification follows the resolved parent context, including roots and remote parents dropped on restart. Legacy constructors preserve compatibility by deriving NONE or LOCAL from the parent ID.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 09d07d7

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 61.28% (+1.05%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 09d07d7 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.83 s 14.74 s [-0.1%; +1.3%] (no difference)
startup:insecure-bank:tracing:Agent 13.58 s 13.72 s [-2.0%; -0.0%] (maybe better)
startup:petclinic:appsec:Agent 17.15 s 16.49 s [-0.3%; +8.2%] (no difference)
startup:petclinic:iast:Agent 17.00 s 17.07 s [-1.3%; +0.5%] (no difference)
startup:petclinic:profiling:Agent 16.64 s 16.09 s [-0.7%; +7.6%] (no difference)
startup:petclinic:sca:Agent 17.12 s 16.90 s [+0.5%; +2.1%] (maybe worse)
startup:petclinic:tracing:Agent 16.13 s 16.29 s [-2.0%; +0.1%] (no difference)

Commit: 09d07d75 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@mcculls mcculls left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems reasonable to me

@mhlidd
mhlidd added this pull request to the merge queue Nov 16, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-16 14:31:04 UTC ℹ️ Start processing command /merge


2026-11-16 14:31:09 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-16 15:41:55 UTC ❌ MergeQueue: The build pipeline contains failing jobs for this merge request

Build pipeline has failing jobs for baa4061:

⚠️ Do NOT retry failed jobs directly (why?).

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.
Details

Since those jobs are not marked as being allowed to fail, the pipeline will most likely fail.
Therefore, and to allow other builds to be processed, this merge request has been rejected and the pipeline got canceled.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 16, 2026
@mhlidd
mhlidd added this pull request to the merge queue Nov 16, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-16 18:07:52 UTC ℹ️ Start processing command /merge


2026-11-16 18:07:56 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-16 19:08:56 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 16, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit e5fdfc1 into master Nov 16, 2026
701 of 704 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the matthew.li/span-context-parent-origin branch November 16, 2026 19:08
@github-actions github-actions Bot added this to the 1.70.0 milestone Nov 16, 2026
dougqh added a commit that referenced this pull request Nov 16, 2026
…-known-custom

Resolves #12998's package move (datadog.contract.Restricted) and adapts
master's #13452 and SpanKind changes to the split stores: the new
DDSpanContext constructor drops the removed tagsSize parameter, and
seedAbsentSpanKind checks and stores span.kind through knownTags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Nov 17, 2026
)

Have the span own its tag stores directly

DDSpanContext holds its IdStore (also its tag lock) and its HashStore
instead of one TagMap, and routes each write to the store that holds the
tag: a name is resolved once and routed, and a write by id goes straight
to the id store. The custom store is borrowed read-only from the
read-through parent until the span's first custom write.

The eager post-processors already read and write the span through
TagStore. The lazy post-processors and the serializer still take a
TagMap: the span builds a view over its stores once, at serialization,
and caches it (about 32 B per span until they move to TagStore).

TagMap.Internals, the core's trusted side door, is gone: the stores are
the direct path. The constructors drop the unused tagsSize parameter.

Allocation, 7-span web-request trace: +104 B (+1.3%), from the new
DDSpanContext fields (8 B per span) and the first custom store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Use the bare KnownTags id names

#13061 named an id after its tag with no _ID suffix. Rename only; the
ids are the same values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Remove the tag when a map write carries a null value

setAllTags and unsafeSetTag passed null values straight to the stores, which
take none, leaving a null-valued entry: the tag still showed in getTags() and
could break serialization. TagMap.set removed the tag on null, as setTag does;
route a null to removal again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Keep copying root-span tags locally when exporting OTLP

With builder-tag precedence, root spans read their trace-level tags through a
shared parent. The OTLP span writer emits only a span's own tags, so root-only
tags (process_id, runtime-id, language, profiling) dropped out of OTLP exports.
Turn the read-through off when OTLP export is on, decided once at startup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy root-span tags into root spans again instead of reading them through

With builder-tag precedence, root spans read their root-span tags through a
shared frozen parent. A parent is always the lowest layer, which is the same as
applying it first, but root tags used to be applied after the inbound request's
tags: a request header mapped onto a root-tag name (process_id, runtime-id,
language, ...) now overrode it. The OTLP span writer also emits only local
tags, so it lost them.

Copy root tags into root spans again, as on master. Only the merged tracer
tags, which were already applied first, stay in the read-through parent. That
also makes the OTLP-export exception unnecessary. Root spans keep about 5-7
more tags locally.

RootSpanTagsReadThroughTest becomes RootSpanTagsTest, which checks root and
child spans in both precedence modes and that root tags win over same-named
inbound tags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Merge remote-tracking branch 'origin/master' into dougqh/tagmap-split-known-custom

Store setAllTags entries with the id already looked up

setAllTags resolved each name to choose the interceptor, then stored the
tag through unsafeSetTag, which resolved it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Drop the name-only routeSet overloads

Each hid a KnownTagCodec.keyOf call, which is how setAllTags came to look
a name up twice. Callers now resolve the id themselves, so every lookup is
visible where it happens; setMetric does it before taking the lock. The
comment introducing the route methods moves to where they start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Set the by-name map's db.pool.name by name again

A rename turned DB_POOL_NAME_NAME into the id constant, so the test's
by-name map set that tag by id, and still passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Trim the knownTags Javadoc to what the field needs; use SPAN_KIND_NAME

The Storage section repeated what customTags and tagView say, and the
rest is now the lock's scope, why it is reentrant, and who skips it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Trim the tag storage comments; post-processors don't call span setters

The knownTags Javadoc said post-processors call back into the span's
setters while the lock is held. None does: they write through the view.
If one did, a custom tag written through the view could miss the span,
so tagView now states the rule, and the rest of the comments are trimmed
or dropped where the code says it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Merge remote-tracking branch 'origin/master' into dougqh/tagmap-split-known-custom

Resolves #12998's package move (datadog.contract.Restricted) and adapts
master's #13452 and SpanKind changes to the split stores: the new
DDSpanContext constructor drops the removed tagsSize parameter, and
seedAbsentSpanKind checks and stores span.kind through knownTags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Co-authored-by: douglas.hawkins <douglas.hawkins@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants