-
Notifications
You must be signed in to change notification settings - Fork 438
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: propagate _dd.p.upstream_services tags #1082
Conversation
ddtrace/tracer/spancontext.go
Outdated
@@ -217,7 +235,13 @@ func (t *trace) setSamplingPriorityLocked(p float64) { | |||
if t.priority == nil { | |||
t.priority = new(float64) | |||
} | |||
*t.priority = p | |||
*t.priority = float64(p) | |||
encodedService := b64Encode(service) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should only keep of the current priority, rate and the sampler name, and avoid re-encoding this every time.
At the very end, we just append to this tag.
8294fc2
to
1fb68a2
Compare
035ca27
to
197acb8
Compare
afa8ecc
to
6dff09c
Compare
won't break the current appsec spec
bfc09a1
to
3573402
Compare
b333743
to
93efac7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're getting closer to a final implementation.
ddtrace/tracer/span.go
Outdated
@@ -283,10 +304,14 @@ func (s *span) setMetric(key string, v float64) { | |||
} | |||
delete(s.Meta, key) | |||
switch key { | |||
case ext.ManualKeep: | |||
if v == float64(samplerAppSec) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite nasty. But I can't think of a better approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just a few nits. Would love it if @knusbaum could also take a look, just in case he notices something I didn't.
ddtrace/tracer/sampler.go
Outdated
// and it's noop except propagating the decision. | ||
samplerNone samplerName = math.MinInt8 | ||
// samplerUnknown specifies that the span was sampled | ||
// but, the tracer was unable to identify the sampler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this possible? In what scenarios?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used in Go tracer. This is reserved value for other tracers in case they are not able to find out who triggered the sampling decision. I can remove it to avoid confusions. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it's never used in the code, but it is in the RFC. I'm OK keeping it here for completeness. The RFC document doesn't say anything about when it can happen...
ddtrace/tracer/sampler.go
Outdated
// samplerUnknown specifies that the span was sampled | ||
// but, the tracer was unable to identify the sampler. | ||
samplerUnknown samplerName = -1 | ||
// samplerDefault specifies that the span was sampled without any sampler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this different from samplerUnknown
? These 3 are still confusing and the documentation doesn't clarify the confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was supposed to be used until the sampling rates come from the agent for the first time.
But, I didn't implement that logic in this PR. We can do it later.
I can remove samplerDefault
from this PR now, then add back when we implement that logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good. I have a few comments.
ddtrace/tracer/span.go
Outdated
case ext.ManualKeep: | ||
if v == float64(samplerAppSec) { | ||
s.setSamplingPriorityLocked(ext.PriorityUserKeep, samplerAppSec, math.NaN()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is here so we can set ManualKeep
with a particular sampler (span.SetTag(ext.ManualKeep, samplerAppSec)
)
Doesn't this case cause ext.ManualKeep to not be set unless by the samplerAppSec
? Do we want ext.ManualKeep
to work for other samplers? That would be a lot more consistent rather than having this special case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this case cause ext.ManualKeep to not be set unless by the samplerAppSec?
No, span.SetTag(ext.ManualKeep, true)
still works as before.
Do we want ext.ManualKeep to work for other samplers?
I think we shouldn't support/allow customer specifying the sampler freely. This was a small hack for AppSec, because AppSec library cannot access private properties/methods of the tracer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, span.SetTag(ext.ManualKeep, true) still works as before.
I know that still works. What I mean is that setting manual keep with any other sampler value will silently fail, and unless I read the setMetric
code, I have no way to know that. This will be surprising behavior if I see appsec setting the sampler with this mechanism.
If we want to do this hack, we should expose samplerAppSec
as some internal
constant so that appsec can use it. I guess it would have to be in github.com/DataDog/dd-trace-go.v1/internal
. We should also document the mechanism (not in the public docs) so we know what works (only samplerAppSec
)
ddtrace/tracer/sampler.go
Outdated
// and it's noop except propagating the decision. | ||
samplerNone samplerName = math.MinInt8 | ||
// samplerUnknown specifies that the span was sampled | ||
// but, the tracer was unable to identify the sampler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it's never used in the code, but it is in the RFC. I'm OK keeping it here for completeness. The RFC document doesn't say anything about when it can happen...
ddtrace/tracer/span.go
Outdated
case ext.ManualKeep: | ||
if v == float64(samplerAppSec) { | ||
s.setSamplingPriorityLocked(ext.PriorityUserKeep, samplerAppSec, math.NaN()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, span.SetTag(ext.ManualKeep, true) still works as before.
I know that still works. What I mean is that setting manual keep with any other sampler value will silently fail, and unless I read the setMetric
code, I have no way to know that. This will be surprising behavior if I see appsec setting the sampler with this mechanism.
If we want to do this hack, we should expose samplerAppSec
as some internal
constant so that appsec can use it. I guess it would have to be in github.com/DataDog/dd-trace-go.v1/internal
. We should also document the mechanism (not in the public docs) so we know what works (only samplerAppSec
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one more nitpick from me.
internal/appsec/waf.go
Outdated
// samplerAppSec specifies that the span was sampled by AppSec. | ||
samplerAppSec int8 = 5 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's point at ddtrace/tracer/sampler.go
here if we're not going to share the definitions. Otherwise I have no idea of the context of 5
.
9293b0b
to
44f2399
Compare
ddtrace/tracer/sampler.go
Outdated
// samplerManual specifies that the span was sampled manually by user. | ||
samplerManual samplerName = 4 | ||
// samplerAppSec specifies that the span was sampled by AppSec. | ||
samplerAppSec samplerName = 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I suggested the same thing. If others agree, let's go ahead and move all of these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the state of the PR to a non-approved state.
44f2399
to
0a4ded8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good regarding internal/appsec/*
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one comment, but not a blocker (it's not something you changed).
Everything looks good. 👍
case int8: | ||
return float64(i), true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's surprising that this was missing. We should probably go ahead and also add uint8
for completeness.
This commit reverts part of: ddtrace/tracer: propagate _dd.p.upstream_services tags #1082
This commit reverts part of: ddtrace/tracer: propagate _dd.p.upstream_services tags #1082
Changes
_dd.p.upstream_services
that holds the services changed sampling decisions.