-
Notifications
You must be signed in to change notification settings - Fork 294
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
dont send traces to agent for routes on blocklist #1989
Conversation
@@ -59,6 +60,16 @@ class HttpServerPlugin extends Plugin { | |||
|
|||
web.wrapRes(context, context.req, context.res, context.res.end)() | |||
}) | |||
|
|||
this.addSub('datadog:tracer:trace:finish', ({ traces }) => { | |||
if (!this.config.blocklist || traces.length === 0) return undefined |
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.
undefined
is redundant as it's the default.
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 should also be an additional check that the root span is actually an HTTP request.
|
||
const urlParts = url.parse(traces[0].meta['http.url']) | ||
|
||
if (this.config.blocklist.includes(urlParts.pathname)) { |
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.
What about allowlist
?
@@ -59,6 +60,16 @@ class HttpServerPlugin extends Plugin { | |||
|
|||
web.wrapRes(context, context.req, context.res, context.res.end)() | |||
}) | |||
|
|||
this.addSub('datadog:tracer:trace:finish', ({ traces }) => { |
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.
traces
should be trace
or spans
.
it('should drop traces for blocklist route', done => { | ||
const spy = sinon.spy(() => { | ||
agent | ||
.use((traces, spy) => { |
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 should be calling the spy, otherwise this test will always pass even if there is a request to the agent.
}, 100) | ||
|
||
axios.get(`http://localhost:${port}/health`).catch(done) | ||
expect(spy).to.not.have.been.called |
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.
The expect should be in the timer otherwise this will always be true.
a22db64
to
4047fcb
Compare
@@ -59,6 +60,20 @@ class HttpServerPlugin extends Plugin { | |||
|
|||
web.wrapRes(context, context.req, context.res, context.res.end)() | |||
}) | |||
|
|||
this.addSub('datadog:tracer:trace:finish', ({ spans }) => { | |||
if ((!this.config.blocklist && !this.config.allowlist) || |
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 use the existing helper to keep this code light.
spans[0].name !== 'http.request') { | ||
return | ||
} | ||
const urlParts = url.parse(spans[0].meta['http.url']) |
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.
Do we really need to parse?
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.
blocklist array only contain the endpoints and not the full url, so I assume we would need to parse?
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.
OK, but let's use the URL constructor here.
4047fcb
to
8b2367e
Compare
spans[0].name !== 'http.request') { | ||
return | ||
} | ||
const urlParts = url.parse(spans[0].meta['http.url']) |
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.
OK, but let's use the URL constructor here.
.use((traces) => { | ||
spy() | ||
}) | ||
.then(done) |
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.
If a trace is received before 100ms, this test will pass. As an alternative here, try removing the then
. The only success case here should be when the spy has not been called after 100ms.
8b2367e
to
8703bad
Compare
Co-authored-by: Ayan Khan <ayan.khan@datadoghq.com>
Co-authored-by: Ayan Khan <ayan.khan@datadoghq.com>
What does this PR do?
don't send traces to agent for routes on blocklist
Motivation
to fix a regression in pkg version 2.x.x where tracer would still export traces to agent for routers that were on blocklist
Plugin Checklist
Additional Notes