-
Notifications
You must be signed in to change notification settings - Fork 540
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
coordinate first pass at ESM support for all instrumentations #1942
Comments
notes on fastify ESM supportFastify ESM support is slightly limited. The current import style in "opentelemetry-js-contrib/plugins/node/opentelemetry-instrumentation-fastify/test/fixtures/use-fastify.mjs" works, but this fails: ...
import * as mod from 'fastify';
console.log('mod: ', mod);
const app = mod.fastify();
... Here |
According to this post, the following already work, based likely on luck:
Your checklist only supports binary display - either fully working or not working at all. How about adding emojis to the list to signal the current implementation status? States could be:
|
🎉 I found a working solution here! My project is using esm and I switched my runtime from If we are living in a simulation then this is a complete cheat code 🥷🏼 |
Heh. I don't object to more info being included in each bullet point. I'd like to keep the checkboxes. To me "checked" will mean "we've done a first pass on ESM instrumentation for this module". When everything is checked, we can close this issue. There could be separate follow-up issues for particular limitations. |
*Description of changes:* 1. Add `IS_ESM` check in `otel_instrument` wrapper before calling lambda handler. If it is EMS format, add ESM node-options [supported](https://github.com/open-telemetry/opentelemetry-js/blob/966ac176af249d86de6cb10feac2306062846768/doc/esm-support.md#esm-options-for-different-versions-of-nodejs) by OTel community. Added a new wrapper script `otel_instrument_esm` if the esm auto detection logic is failed, customer can opt-in to tell tell layer go with ESM instrumentation path. 2. Set a new env var `HANDLER_IS_ESM` for lambda function when ESM is detected 3. Patch aws-lambda instrumentation, when `IS_ESM` env var is set, apply ESM supported `InstrumentationNodeModuleDefinition` to patch function handler, otherwise keep using the existing handler patcher. Note: this change add a new branch for supporting ESM, the existing CommonJS path should not be impacted. 1. open-telemetry/opentelemetry-js#4842 2. open-telemetry/opentelemetry-js-contrib#1942 *Test* ``` 2024-10-09T20:38:13.411-07:00 | Instrumenting lambda handler { -- | -- | 2024-10-09T20:38:13.411-07:00 | taskRoot: '/var/task', | 2024-10-09T20:38:13.411-07:00 | handlerDef: 'index.handler', | 2024-10-09T20:38:13.411-07:00 | handler: 'index.handler', | 2024-10-09T20:38:13.411-07:00 | moduleRoot: '', | 2024-10-09T20:38:13.411-07:00 | module: 'index', | 2024-10-09T20:38:13.411-07:00 | filename: '/var/task/index.mjs', | 2024-10-09T20:38:13.411-07:00 | functionName: 'handler' | 2024-10-09T20:38:13.411-07:00 | } | 2024-10-09T20:38:15.386-07:00 | 'cloud.account.id': '252610625673', -- | -- | -- | 2024-10-09T20:38:15.386-07:00 | 'aws.is.local.root': true, | 2024-10-09T20:38:15.386-07:00 | 'aws.local.service': 'TestESM', | 2024-10-09T20:38:15.386-07:00 | 'aws.local.operation': 'TestESM/Handler', | 2024-10-09T20:38:15.386-07:00 | 'aws.span.kind': 'LOCAL_ROOT' ``` By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
This is a meta issue to coordinate doing a first pass at ECMAScript module (ESM) support and a test for every node.js instrumentation. (This is about working with the
import-in-the-middle
-based hook so is not relevant to browser instrumentations.) I'm not necessarily volunteering to do all these :), but I'll certainly help.Hopefully this can also be useful for support/help requests for why instrumentation might not be working for ESM-using code. If the module/instrumentation in question is not checked off here, then ESM instrumentation is not expected to work (it might be luck).
.mjs
) handlers #2508, missing test)dev notes
Run the following to show which (contrib-repo) instrumentations have an ESM-related test.
This shows usage of the required experimental-loader hook to support hooking ESM modules.
Guide on adding ESM support and an ESM test to an instrumentation
TODO(trentm)
runTestFixture
The text was updated successfully, but these errors were encountered: