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

ddtrace/tracer: don't set empty tracestate propagation tag #1910

Merged
merged 1 commit into from Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions ddtrace/tracer/textmap.go
Expand Up @@ -896,6 +896,11 @@ func parseTraceparent(ctx *spanContext, header string) error {
// `origin` = `o`
// `_dd.p.` prefix = `t.`
func parseTracestate(ctx *spanContext, header string) error {
if header == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to do this empty check in both places? (If so maybe we should duplicate this comment in both places to make it obvious why it's alright for it to be empty)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, the empty check here should be enough! (PR updated)

// The W3C spec says tracestate can be empty but should avoid sending it.
// https://www.w3.org/TR/trace-context-1/#tracestate-header-field-values
return nil
}
// if multiple headers are present, they must be combined and stored
setPropagatingTag(ctx, tracestateHeader, header)
list := strings.Split(strings.Trim(header, "\t "), ",")
Expand Down
10 changes: 10 additions & 0 deletions ddtrace/tracer/textmap_test.go
Expand Up @@ -899,6 +899,16 @@ func TestEnvVars(t *testing.T) {
origin string
propagatingTags map[string]string
}{
{
in: TextMapCarrier{
traceparentHeader: "00-00000000000000001111111111111111-2222222222222222-01",
// no tracestate header, shouldn't put an empty tracestate in propagatingTags
},
tid: traceIDFrom64Bits(1229782938247303441),
out: []uint64{2459565876494606882, 1},
origin: "",
propagatingTags: *(new(map[string]string)),
},
{
in: TextMapCarrier{
traceparentHeader: "00-00000000000000001111111111111111-2222222222222222-01",
Expand Down