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

fix(instrumentation-http): fix http/https ESM instr for 'import defaultExport from' style #5075

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

trentm
Copy link
Contributor

@trentm trentm commented Oct 16, 2024

Fix instrumentation of http.get, http.request, https.get, and
https.request when used from ESM code and imported via the import defaultExport from 'http' style.

Fixes: #5024

…ltExport from' style

Fix instrumentation of `http.get`, `http.request`, `https.get`, and
`https.request` when used from ESM code and imported via the `import
defaultExport from 'http'` style.

Fixes: open-telemetry#5024
@trentm trentm self-assigned this Oct 16, 2024
@trentm trentm requested a review from a team as a code owner October 16, 2024 20:15
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.26%. Comparing base (5e17361) to head (8e6afd9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5075      +/-   ##
==========================================
- Coverage   93.27%   93.26%   -0.02%     
==========================================
  Files         317      317              
  Lines        8195     8195              
  Branches     1641     1641              
==========================================
- Hits         7644     7643       -1     
- Misses        551      552       +1     

see 1 file with indirect coverage changes

request: httpRequestC,
get: httpGetC,
},
];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer note: Be sure to use the "Hide whitespace" option for looking at this diff. There is an indentation change, so the diff is much smaller without the whitespace.

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the thorough investigation and for providing this fix @trentm 🙂
I tested this with the reproducer from #5024 and it works perfectly 👍

if (!this.getConfig().disableOutgoingRequestInstrumentation) {
const patchedRequest = this._wrap(
moduleExports,
'request',
this._getPatchOutgoingRequestFunction('http')
) as unknown as Func<http.ClientRequest>;
this._wrap(
const patchedGet = this._wrap(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, my IDE complains here as we're using a void return type. It looks though that the types for shimmer are actually incorrect here as it does, in fact, return something: https://github.com/othiym23/shimmer/blob/b2b29d760aa664767f71f37dbcbfac0b9250421b/index.js#L57

Maybe we should note this in a comment for future reference. 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pichlermarc Hrm, I don't get that complaint in VS Code (nor in 'npm run lint' or warnings from 'npm run compile'). I'm a little curious what our config differences are here. I haven't spent time polishing VS Code config.

It looks though that the types for shimmer are actually incorrect here

So I guess this would be a bug against https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/shimmer/index.d.ts
Without some way to show that error or warning, I don't yet want to create the issue for that.

@trentm trentm added this pull request to the merge queue Oct 22, 2024
Merged via the queue into open-telemetry:main with commit 55a1fc8 Oct 22, 2024
21 checks passed
@trentm trentm deleted the tm-instr-http-esm branch October 22, 2024 19:53
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.

instrumentation-http: ESM instrumentation does not work on outgoing requests
2 participants