ddtrace/tracer/textmap: Setting _dd.propagation_error tag on faulty context propagation#1969
ddtrace/tracer/textmap: Setting _dd.propagation_error tag on faulty context propagation#1969dianashevchenko wants to merge 5 commits into
Conversation
ajgajg1134
left a comment
There was a problem hiding this comment.
overall looks good! Just a few comments in the tests mainly
| } | ||
| if ctx.trace != nil { | ||
| if ctx.trace != nil && ctx.trace.propagatingTag(keyTraceID128) != "" { | ||
| // TODO: this always assumed it was valid so I copied that logic here, maybe we shouldn't |
There was a problem hiding this comment.
looks like we can remove this comment now?
|
|
||
| func TestMalformedTIDPropagationErrorTag(t *testing.T) { | ||
| assert := assert.New(t) | ||
| t.Run("datadog", func(t *testing.T) { |
There was a problem hiding this comment.
Is there a more descriptive name for this and the next test?
| root := tracer.StartSpan("web.request", ChildOf(sctx)).(*span) | ||
| root.Finish() | ||
| assert.Contains(root.Meta, keyPropagationError) | ||
| assert.Equal(root.Meta[keyPropagationError], "malformed_tid XXXXXXXXXXXXXXXX") |
There was a problem hiding this comment.
| assert.Equal(root.Meta[keyPropagationError], "malformed_tid XXXXXXXXXXXXXXXX") | |
| assert.Equal("malformed_tid XXXXXXXXXXXXXXXX", root.Meta[keyPropagationError]) |
| root := tracer.StartSpan("web.request", ChildOf(sctx)).(*span) | ||
| root.Finish() | ||
| assert.Contains(root.Meta, keyPropagationError) | ||
| assert.Equal(root.Meta[keyPropagationError], "inconsistent_tid 640cfd8d0000ffff") |
There was a problem hiding this comment.
| assert.Equal(root.Meta[keyPropagationError], "inconsistent_tid 640cfd8d0000ffff") | |
| assert.Equal("inconsistent_tid 640cfd8d0000ffff", root.Meta[keyPropagationError]) |
| root := tracer.StartSpan("web.request", ChildOf(sctx)).(*span) | ||
| root.Finish() | ||
| assert.Contains(root.Meta, keyPropagationError) | ||
| assert.Equal(root.Meta[keyPropagationError], "malformed_tid XXXX") |
There was a problem hiding this comment.
| assert.Equal(root.Meta[keyPropagationError], "malformed_tid XXXX") | |
| assert.Equal("malformed_tid XXXX", root.Meta[keyPropagationError]) |
| assert := assert.New(t) | ||
| t.Run("datadog", func(t *testing.T) { | ||
| t.Setenv(headerPropagationStyleExtract, "datadog") | ||
| tracer := newTracer(WithPropagator(NewPropagator(nil))) |
There was a problem hiding this comment.
defer tracer.Stop() in these tests to ensure we cleanup the goroutines started that are associated with them
| if len(ctx.trace.propagatingTag(keyTraceID128)) != 16 { | ||
| ctx.trace.unsetPropagatingTag(keyTraceID128) | ||
| } |
There was a problem hiding this comment.
Can we do this below where we're doing the hex parsing instead? Checking the validity of keyTraceID128 in two places makes this a bit more complicated than it needs to be. Plus, we also want to unset this propagating tag if the hex is invalid, so the logic should be the same. Right now, we're still keeping the _dd.p.tid tag even if it's invalid hex, which isn't correct per the RFC:
if the tag value is a valid 32 character lower-case hexadecimal encoded number, set the higher-order 64 bits of the TraceId to its (decoded) value.
if the tag value is malformed, discard the tag value and, optionally, set thedd.propagation_errortag to:
malformed_tid+ <_dd.p.tid value>
| if key == "t.tid" { | ||
| if ok := validIDRgx.MatchString(val); !ok { | ||
| ctx.trace.setTag(keyPropagationError, fmt.Sprintf("malformed_tid %s", val)) | ||
| } else if val != ctx.traceID.UpperHex() { | ||
| ctx.trace.setTag(keyPropagationError, fmt.Sprintf("inconsistent_tid %s", val)) | ||
| } | ||
| } |
There was a problem hiding this comment.
(From Slack convo) this is all optional, right? Based on the RFC and comments, it sounds like it's perfectly valid to just not propagate/use the _dd.p.tid tag when using W3C trace context propagation. If this is optional, then let's not do this unless we have a very compelling reason that it'll help customers. The code is already fairly complicated, so let's avoid doing more than we need to.
i.e. you can just add a continue right here instead if key == "t.tid" to not propagate it.
There was a problem hiding this comment.
I'm not sure I see what you mean. Is that what you suggest ? :
if key == "t.tid" && (val != ctx.traceID.UpperHex() || (!validIDRgx.MatchString(val))) {
continue
}
setPropagatingTag(key, val)|
We already shipped the fix in #2076 and decided to not add the _dd.propagation_error tag so I'm closing this PR. |
What does this PR do?
This PR recognises faulty context propagation when
dd_p.tid(TraceID) is inconsistent or malformedMotivation
Describe how to test/QA your changes
Reviewer's Checklist