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 wrapping ESM files with absolute path #5094

Conversation

serkan-ozal
Copy link
Contributor

@serkan-ozal serkan-ozal commented Oct 28, 2024

Which problem is this PR solving?

Currently ESM files are not able to instrumented with absolute path, but as modules. Instrumenting ESM files with absolute path is needed for AWS Lambda functions, as ESM based handlers are supported since long time (https://aws.amazon.com/tr/about-aws/whats-new/2022/01/aws-lambda-es-modules-top-level-await-node-js-14/)

For example, here is the issue we have faced in AWS Lambda Node.js layer: open-telemetry/opentelemetry-lambda#1557

Note: To have ESM support for AWS Lambda functions, there will be subsequent PRs to the opentelemetry-js-contrib and opentelemetry-lambda repositories based on this.

Short description of the changes

When ESM files to be instrumented are provided with their absolute paths, import-in-the-middle library passes module name parameter as full path without any baseDir parameter (but require-in-the-middle library doesn't work like this for the instrumentation of the CommonJS modules).

However, _onRequire method requires those parameters with proper values (name as filename and baseDir as the directory of the file). So, this PR makes the required conversion for the name and baseDir parameters to be able to used properly by the _onRequire method.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Added tests to experimental/packages/opentelemetry-instrumentation/test/node/EsmInstrumentation.test.mjs

  • EsmInstrumentation.test

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@serkan-ozal serkan-ozal requested a review from a team as a code owner October 28, 2024 15:07
Copy link

codecov bot commented Oct 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.17%. Comparing base (6f4f3fc) to head (784b805).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5094   +/-   ##
=======================================
  Coverage   93.17%   93.17%           
=======================================
  Files         315      315           
  Lines        8086     8086           
  Branches     1617     1617           
=======================================
  Hits         7534     7534           
  Misses        552      552           

@serkan-ozal serkan-ozal force-pushed the fix/instrumentation/wrap-esm-with-absolute-path branch from f356048 to 123fac0 Compare October 28, 2024 15:57
@serkan-ozal serkan-ozal marked this pull request as draft October 28, 2024 16:04
@serkan-ozal serkan-ozal force-pushed the fix/instrumentation/wrap-esm-with-absolute-path branch from 123fac0 to 7c2f321 Compare October 28, 2024 16:06
@serkan-ozal serkan-ozal force-pushed the fix/instrumentation/wrap-esm-with-absolute-path branch from 7c2f321 to 82379b8 Compare October 28, 2024 16:15
@serkan-ozal serkan-ozal marked this pull request as ready for review October 28, 2024 16:22
@pragmaticivan
Copy link
Contributor

🔥

Copy link
Member

@JamieDanielson JamieDanielson left a comment

Choose a reason for hiding this comment

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

Thanks @serkan-ozal can you also add a changelog entry?

@pichlermarc pichlermarc added bug Something isn't working pkg:instrumentation-http labels Nov 6, 2024
@serkan-ozal
Copy link
Contributor Author

@JamieDanielson @dyladan Done. Added README. All is green now.

@trentm trentm added this pull request to the merge queue Nov 6, 2024
Merged via the queue into open-telemetry:main with commit fe4d368 Nov 6, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:instrumentation-http
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants