-
Notifications
You must be signed in to change notification settings - Fork 227
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
fix: ensure the span run-context for outgoing http requests does not spill into user code #2470
Conversation
…ill into user code This fixes the 'http' and 'https' instrumentation for outgoing requests to not have the 'http' span context be active in user code. This ensures that user code cannot create a child span of the http span, which would (a) be misleading and (b) cause problems for coming exit span and compressed span work. Refs: #2430
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
🤖 GitHub commentsTo re-run your PR in the CI, just comment with:
|
The tests were failing on this (with some added
The issue is that we are accidentally instrumenting the outgoing http request attempts being done for cloud metadata fetching... and doing so with the agent in a state here:
a fixA possible fix is to tweak "lib/http-request.js" (as we already did for the elastic-apm-http-client in elastic/apm-nodejs-http-client#161) to get early references to
|
There was a bug in the https instrumentation in older versions of node (version <9.0.0) where the instrumentation of `https.request` relied on intercepting `http.request` (that Node's `https.request()` would call). However, the agent didn't guarantee that the 'http' module was instrumented. A user program that used `https.request` without indirectly `require('http')`ing would not get an HTTP span. Also change some test fixtures to use {http,https}.request() usage to a form supported in versions of node before v10.9.0 to be able to test with node v8.
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.
👍 Approving.
I see here that we've taken steps to ensure the request methods used by the agent are uninstrumented functions.
I also see that we're binding a request's callback to the run context that was active when the request was made.
I see we're invoking the original request using a new run context created via the parent run context's enterSpan
method.
Finally, in the response event handler, I see we're ensuring the response is bound to the parent's run context.
…spill into user code (#2470) This fixes the 'http' and 'https' instrumentation for outgoing requests to not have the 'http' span context be active in user code. This ensures that user code cannot create a child span of the http span, which would (a) be misleading and (b) cause problems for coming exit span and compressed span work. Also, fix a bug in the https instrumentation in older versions of node (version <9.0.0) where the instrumentation of `https.request` relied on intercepting `http.request` (that Node's `https.request()` would call). The agent didn't guarantee that the 'http' module was instrumented. A user program that used `https.request` without indirectly `require('http')`ing would not get an HTTP span. Refs: #2430
This fixes the 'http' and 'https' instrumentation for outgoing requests
to not have the 'http' span context be active in user code. This ensures
that user code cannot create a child span of the http span, which would
(a) be misleading and (b) cause problems for coming exit span and
compressed span work.
Refs: #2430
Checklist