-
Notifications
You must be signed in to change notification settings - Fork 837
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
feat(instrumentation): support ESM in node via import-in-the-middle #2640
Conversation
@@ -17,6 +17,7 @@ | |||
import * as types from '../../types'; | |||
import * as path from 'path'; | |||
import * as RequireInTheMiddle from 'require-in-the-middle'; | |||
import ImportInTheMiddle from 'require-in-the-middle'; |
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 IITM not RITM right?
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.
Whoops! Fixing this now.
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.
Fixed, I think. 😅
To answer the question of tests: I know there's full integration tests in https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts#L223 etc. -- that verify spans are created when instrumentation is hooked, you'd just need to run under ESM in order to force the import to happen with ESM rather than it being converted to a require. Likewise https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L86 is exercised by https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-package.test.ts |
@@ -29,7 +30,7 @@ export abstract class InstrumentationBase<T = any> | |||
extends InstrumentationAbstract | |||
implements types.Instrumentation { | |||
private _modules: InstrumentationModuleDefinition<T>[]; | |||
private _hooks: RequireInTheMiddle.Hooked[] = []; | |||
private _hooks = 0; |
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.
i think we can remove this altogether and only use _enabled
?
I've launched the tests suite for the PR and it seems there are issue with our typescript config, do you think you could look into it ? |
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
Please keep this open, I think this feature should be still considered for adoption. |
I've rebased this as #2763 |
Any Update on this ? we would also like to have ESM support |
Would LOVE to see this get pulled in, this is massive! |
Completed in #3698, huge thanks to everyone involved 🙂 |
Which problem is this PR solving?
Node.js ESM support.
Short description of the changes
Adds
import-in-the-middle
alongsiderequire-in-the-middle
. Also avoids hanging on to the hooks, because they're unnecessary (not used in disable).Type of change
How Has This Been Tested?
The existing tests pass. The part of code that uses
require-in-the-middle
does not appear to be tested by the test files in the package. Are there other tests elsewhere that cover it? If so, happy to add appropriate tests there. I'll call this a draft until there's something better here.Checklist: