Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] unable to extract traceparent header #2494

Open
tylerbrewer2 opened this issue Jan 9, 2024 · 3 comments
Open

[BUG] unable to extract traceparent header #2494

tylerbrewer2 opened this issue Jan 9, 2024 · 3 comments
Labels
bug unintended behavior that has to be fixed

Comments

@tylerbrewer2
Copy link

tylerbrewer2 commented Jan 9, 2024

I'm attempting to create a span from an Opentelemetry trace id using the ddtrace Go library. It doesn't look like the library is parsing my traceparent header correctly. I've searched for more documentation around this and couldnt find any, although I could be missing it.

Here is my simplified code:

sctx, _ := tracer.Extract(tracer.HTTPHeadersCarrier(header))
span := tracer.StartSpan(operation, tracer.ChildOf(sctx))
logger.Info(fmt.Sprintf("Span Trace ID: %d", span.Context().TraceID())) // this will always be 0

And here is an example traceparent header: 00-5561fab7902a8debd3e3ae2dd534e52d-824e6ffb17187dcd-00

Version of dd-trace-go
1.59.0

Describe what happened:
The created span is not associated with the parent span.

Describe what you expected:
The created span to be associated with the parent span.

@tylerbrewer2 tylerbrewer2 added the bug unintended behavior that has to be fixed label Jan 9, 2024
@github-actions github-actions bot added the needs-triage New issues that have not yet been triaged label Jan 9, 2024
@darccio
Copy link
Member

darccio commented Jan 15, 2024

@tylerbrewer2 How is your header value looking?

@darccio darccio removed the needs-triage New issues that have not yet been triaged label Jan 15, 2024
@tylerbrewer2
Copy link
Author

Here are my headers:

Sec-Fetch-Mode: cors
Accept-Encoding: gzip, deflate
Content-Length: 0
Host: 127.0.0.1:8090
Connection: keep-alive
Traceparent: 00-e73ce4a976cb18ac8d648239cc60e26f-ee91c28519b9f401-01
Accept: */*
Content-Type: application/proto
Accept-Language: *
User-Agent: undici

@darccio
Copy link
Member

darccio commented Jan 19, 2024

@tylerbrewer2 I just tested it in our current main branch, and it seems to work.

func TestHTTPHeadersCarrierExtract(t *testing.T) {
	tracer := newTracer()
	internal.SetGlobalTracer(tracer)
	defer tracer.Stop()
	r := &http.Request{
		Header: http.Header{
			"Sec-Fetch-Mode":  []string{"cors"},
			"Accept-Encoding": []string{"gzip, deflate"},
			"Content-Length":  []string{"0"},
			"Host":            []string{"127.0.0.1:8090"},
			"Connection":      []string{"keep-alive"},
			"Traceparent":     []string{"00-e73ce4a976cb18ac8d648239cc60e26f-ee91c28519b9f401-01"},
			"Accept":          []string{"*/*"},
			"Content-Type":    []string{"application/proto"},
			"Accept-Language": []string{"*"},
			"User-Agent":      []string{"undici"},
		},
	}
	header := HTTPHeadersCarrier(r.Header)
	sCtx, _ := Extract(header)
	span := StartSpan("operation", ChildOf(sCtx))
	assertions := assert.New(t)
	sp, ok := span.Context().(ddtrace.SpanContextW3C)
	assertions.True(ok)
	assertions.NotZero(sp.TraceID128())
	t.Logf("traceID: %s", sp.TraceID128())
}

image

Do you observe any difference between my example and your code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unintended behavior that has to be fixed
Projects
None yet
Development

No branches or pull requests

2 participants