Skip to content

fix(span): skip zero parent span id from empty traceparent (#23)#25

Merged
tobert merged 1 commit intomainfrom
fix/tp-ignore-env-zeros
Feb 9, 2026
Merged

fix(span): skip zero parent span id from empty traceparent (#23)#25
tobert merged 1 commit intomainfrom
fix/tp-ignore-env-zeros

Conversation

@tobert
Copy link
Owner

@tobert tobert commented Feb 9, 2026

Summary

  • When --tp-ignore-env is set, LoadTraceparent() returns a traceparent with Initialized=true but zeroed SpanId
  • The code unconditionally set ParentSpanId = tp.SpanId, producing a span with an all-zeros parent
  • Now checks bytes.Equal against GetEmptySpanId() before setting parent span id
  • Added functional test that verifies --tp-ignore-env produces empty parent span id

Test plan

  • New functional test in data_for_test.go: --tp-ignore-env with TRACEPARENT set, verify parent_span_id is empty
  • All existing tests pass (go test && go test ./...)

Fixes #23

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 9, 2026 00:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes span parent linkage when a traceparent is “initialized” but has an all-zero SpanID (notably with --tp-ignore-env), preventing emission of a zero-valued parent_span_id.

Changes:

  • Prevent setting ParentSpanId when the loaded traceparent SpanID is empty/all-zeros.
  • Add a functional fixture verifying --tp-ignore-env results in an empty parent_span_id.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
otelcli/config_span.go Adds a guard to avoid assigning an all-zero parent span id from traceparent.
data_for_test.go Adds a functional test/fixture to validate empty parent_span_id behavior with --tp-ignore-env.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 44 to +47
if tp.Initialized {
span.TraceId = tp.TraceId
span.ParentSpanId = tp.SpanId
// only set parent span id when the traceparent has a real (non-zero) span id (#23)
if !bytes.Equal(tp.SpanId, otlpclient.GetEmptySpanId()) {
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

Minor readability improvement: consider storing otlpclient.GetEmptySpanId() in a local variable (e.g., emptySpanID := ...) before the if, so the comparison reads more clearly and avoids repeating a function call in the condition.

Suggested change
if tp.Initialized {
span.TraceId = tp.TraceId
span.ParentSpanId = tp.SpanId
// only set parent span id when the traceparent has a real (non-zero) span id (#23)
if !bytes.Equal(tp.SpanId, otlpclient.GetEmptySpanId()) {
emptySpanID := otlpclient.GetEmptySpanId()
if tp.Initialized {
span.TraceId = tp.TraceId
// only set parent span id when the traceparent has a real (non-zero) span id (#23)
if !bytes.Equal(tp.SpanId, emptySpanID) {

Copilot uses AI. Check for mistakes.
Comment on lines +1246 to +1249
// #23: --tp-ignore-env should not produce a zero-valued parent span id
{
{
Name: "#23 --tp-ignore-env should not send zero parent span id",
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The comment says “zero-valued parent span id”, but the assertion checks for an empty string (i.e., omitted/empty parent_span_id), not the all-zeros hex representation. Consider rewording the comment and/or test name to explicitly say the parent span id should be empty/omitted (and not 0000000000000000).

Suggested change
// #23: --tp-ignore-env should not produce a zero-valued parent span id
{
{
Name: "#23 --tp-ignore-env should not send zero parent span id",
// #23: --tp-ignore-env should result in an empty/omitted parent span id (not 0000000000000000)
{
{
Name: "#23 --tp-ignore-env should omit parent span id (empty/omitted, not 0000000000000000)",

Copilot uses AI. Check for mistakes.
Comment on lines +1263 to +1267
SpanData: map[string]string{
"trace_id": "*",
"span_id": "*",
"parent_span_id": "",
},
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The comment says “zero-valued parent span id”, but the assertion checks for an empty string (i.e., omitted/empty parent_span_id), not the all-zeros hex representation. Consider rewording the comment and/or test name to explicitly say the parent span id should be empty/omitted (and not 0000000000000000).

Copilot uses AI. Check for mistakes.
When --tp-ignore-env is set, LoadTraceparent returns a traceparent with
Initialized=true but zeroed SpanId. The code unconditionally copied this
into ParentSpanId, producing a span with an all-zeros parent that looks
like it has a parent when it doesn't.

Now checks bytes.Equal against GetEmptySpanId() before setting parent.

Fixes #23

🤖 Claude <claude@anthropic.com>
@tobert tobert force-pushed the fix/tp-ignore-env-zeros branch from e201890 to 7e73320 Compare February 9, 2026 02:52
@tobert tobert merged commit ed5ef5d into main Feb 9, 2026
1 check passed
@tobert tobert deleted the fix/tp-ignore-env-zeros branch February 9, 2026 02:53
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.

--tp-ignore-env sends zeros rather than removing the parent_id

2 participants