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): do not import 'path' in browser runtimes #4386

Merged
merged 6 commits into from
Jan 3, 2024

Conversation

pichlermarc
Copy link
Member

Which problem is this PR solving?

Since we now export InstrumentationNodeModuleDefinition even if @opentelemetry/instrumentation is used in a browser context. This PR changes it so that it does not import 'path' anymore which is part of the nodejs core library. As only the normalize function is used, I replaced it with a function that throws on runtime should someone use InstrumentationNodeModuleDefinition in the browser for some reason.

Fixes #4373

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • npm packed @opentelemetry/instrumentation locally, installed it in a local reproducer and packaged it with webpack.

@pichlermarc pichlermarc requested a review from a team December 21, 2023 13:41
Copy link

codecov bot commented Dec 21, 2023

Codecov Report

Merging #4386 (b5e33c3) into main (0206181) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4386   +/-   ##
=======================================
  Coverage   92.24%   92.24%           
=======================================
  Files         333      334    +1     
  Lines        9459     9463    +4     
  Branches     2009     2009           
=======================================
+ Hits         8725     8729    +4     
  Misses        734      734           
Files Coverage Δ
...strumentation/src/instrumentationNodeModuleFile.ts 33.33% <100.00%> (ø)
...rumentation/src/platform/browser/noop-normalize.ts 100.00% <100.00%> (ø)

Comment on lines 27 to 29
export function normalize(_path: string): string {
throw new Error('Not implemented');
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we really want this to throw? I think just a no-op that returns the input should be fine. Maybe a diag warning that something unexpected happened?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes a warning will also do the trick - I changed it to a no-op, see aa42161

@pichlermarc pichlermarc merged commit b36ab12 into open-telemetry:main Jan 3, 2024
20 checks passed
@pichlermarc pichlermarc deleted the fix/4373 branch January 3, 2024 16:41
Zirak pushed a commit to Zirak/opentelemetry-js that referenced this pull request Sep 14, 2024
…telemetry#4386)

* fix(instrumentation): do not import 'path' in browser runtimes

* fix(changelog): clean up and add entry

* fix(instrumentation): add missing license header

* fix(changelog): formatting

* fix(instrumentation): do not throw
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] Cannot build web project using webpack due to reference to nodejs core package (path)
3 participants