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

dont send traces to agent for routes on blocklist #1989

Merged
merged 1 commit into from
Apr 22, 2022

Conversation

khanayan123
Copy link
Collaborator

@khanayan123 khanayan123 commented Apr 8, 2022

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

@khanayan123 khanayan123 requested a review from a team as a code owner April 8, 2022 18:49
@khanayan123 khanayan123 requested a review from rochdev April 8, 2022 18:49
@@ -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
Copy link
Member

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.

Copy link
Member

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)) {
Copy link
Member

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 }) => {
Copy link
Member

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) => {
Copy link
Member

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
Copy link
Member

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.

@@ -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) ||
Copy link
Member

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'])
Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

spans[0].name !== 'http.request') {
return
}
const urlParts = url.parse(spans[0].meta['http.url'])
Copy link
Collaborator

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)
Copy link
Collaborator

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.

@rochdev rochdev added this to the 2.5.1 milestone Apr 20, 2022
@khanayan123 khanayan123 merged commit 87f2a81 into master Apr 22, 2022
simon-id pushed a commit that referenced this pull request Apr 27, 2022
Co-authored-by: Ayan Khan <ayan.khan@datadoghq.com>
simon-id pushed a commit that referenced this pull request Apr 27, 2022
Co-authored-by: Ayan Khan <ayan.khan@datadoghq.com>
@tlhunter tlhunter deleted the khanayan123/support-blocklist branch January 19, 2024 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants