Skip to content

Commit

Permalink
ddtrace/tracer: don't set empty tracestate propagation tag (#1910)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-mez committed Apr 17, 2023
1 parent 7883f0e commit 6408430
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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 == "" {
// 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

0 comments on commit 6408430

Please sign in to comment.