-
Notifications
You must be signed in to change notification settings - Fork 340
remove async storage from http2 server instrumentation #5947
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
fe7f4c9
efb43ac
3a5a4b9
f591353
fec0b82
6e4c8d5
df2f297
ee086fb
b88d8f1
5dbad1a
4f2e32b
d984ae5
5d2d2cf
8f22eea
de7e856
2101189
f3b0f95
9280d18
a11dbb2
48b1f1e
1734964
57e0ac6
2d4d910
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,7 @@ | |
|
||
const { | ||
channel, | ||
addHook, | ||
AsyncResource | ||
addHook | ||
} = require('../helpers/instrument') | ||
const shimmer = require('../../../datadog-shimmer') | ||
|
||
|
@@ -30,14 +29,11 @@ function wrapCreateServer (createServer) { | |
} | ||
} | ||
|
||
function wrapResponseEmit (emit) { | ||
const asyncResource = new AsyncResource('bound-anonymous-fn') | ||
function wrapResponseEmit (emit, ctx) { | ||
return function (eventName, event) { | ||
return asyncResource.runInAsyncScope(() => { | ||
if (eventName === 'close' && finishServerCh.hasSubscribers) { | ||
finishServerCh.publish({ req: this.req }) | ||
} | ||
if (eventName !== 'close') return emit.apply(this, arguments) | ||
|
||
return finishServerCh.runStores({ req: this.req, ...ctx }, () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The context should be altered and passed directly instead of creating a new object. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, if I understand the new code correctly, it now restores the parent context here where before it was restoring the current context. This means event listeners will no longer be in the context of the span. I'm not sure which is the expected behaviour, especially if there was no test for this, but to be safe it's probably best to keep the previous behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed this behavior, now it restores the current context. |
||
return emit.apply(this, arguments) | ||
}) | ||
} | ||
|
@@ -51,18 +47,17 @@ function wrapEmit (emit) { | |
if (eventName === 'request') { | ||
res.req = req | ||
|
||
const asyncResource = new AsyncResource('bound-anonymous-fn') | ||
return asyncResource.runInAsyncScope(() => { | ||
startServerCh.publish({ req, res }) | ||
|
||
shimmer.wrap(res, 'emit', wrapResponseEmit) | ||
const ctx = { req, res } | ||
return startServerCh.runStores(ctx, () => { | ||
shimmer.wrap(res, 'emit', emit => wrapResponseEmit(emit, ctx)) | ||
|
||
try { | ||
return emit.apply(this, arguments) | ||
} catch (err) { | ||
errorServerCh.publish(err) | ||
} catch (error) { | ||
ctx.error = error | ||
errorServerCh.publish(ctx) | ||
|
||
throw err | ||
throw error | ||
} | ||
}) | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.