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: Don't use require to load package.json files #4593

Merged
merged 6 commits into from
Apr 15, 2024

Conversation

timfish
Copy link
Contributor

@timfish timfish commented Mar 28, 2024

Which problem is this PR solving?

It's currently not possible to bundle @opentelemetry/instrumentation with many bundlers.

Webpack fails because it errors with Critical dependency: The request of a dependency is an expression. This is because webpack can see the require but can't reason about what is being loaded.

image

Rollup can only bundle the code if you include a plugin that can load json files.

Since auto instrumentation will not work when the code is bundled, why would this change even matter?

Sentry is using @opentelemetry/instrumentation as a dependency in their Node SDK. Some users will not care about instrumentation but will want to bundle their code and using require like this to load json files makes it impossible to use some bundlers or at a minimum requires extra bundler config to work around it.

Short description of the changes

Use readFileSync + JSON.parse instead.

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?

Covered by existing tests

Checklist:

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

@timfish timfish requested a review from a team March 28, 2024 11:36
Copy link

linux-foundation-easycla bot commented Mar 28, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

codecov bot commented Mar 28, 2024

Codecov Report

Merging #4593 (ead0231) into main (c046867) will decrease coverage by 3.58%.
Report is 8 commits behind head on main.
The diff coverage is n/a.

❗ Current head ead0231 differs from pull request most recent head 269e190. Consider uploading reports for the commit 269e190 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4593      +/-   ##
==========================================
- Coverage   92.83%   89.26%   -3.58%     
==========================================
  Files         329      147     -182     
  Lines        9528     3138    -6390     
  Branches     2053      686    -1367     
==========================================
- Hits         8845     2801    -6044     
+ Misses        683      337     -346     

see 190 files with indirect coverage changes

@dyladan
Copy link
Member

dyladan commented Mar 28, 2024

Please add a changelog entry

@timfish
Copy link
Contributor Author

timfish commented Mar 28, 2024

Done. Let me know if I've put it in the wrong changelog!

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.

This looks good, thanks for working on this. 👍

experimental/CHANGELOG.md Outdated Show resolved Hide resolved
@pichlermarc pichlermarc merged commit da02c8d into open-telemetry:main Apr 15, 2024
18 checks passed
@timfish timfish deleted the fix/no-require branch April 16, 2024 00:25
Zirak pushed a commit to Zirak/opentelemetry-js that referenced this pull request Sep 14, 2024
…#4593)

* fix: Don't use require to load package.json files

* update changelog

* Move changelog entry

---------

Co-authored-by: Marc Pichler <[email protected]>
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.

3 participants