Skip to content

fix(opentelemetry-instrumentation): access require via globalThis to avoid webpack analysis#6481

Merged
overbalance merged 2 commits intoopen-telemetry:mainfrom
embrace-io:overbalance/webpack-require-instrumentation
Mar 9, 2026
Merged

fix(opentelemetry-instrumentation): access require via globalThis to avoid webpack analysis#6481
overbalance merged 2 commits intoopen-telemetry:mainfrom
embrace-io:overbalance/webpack-require-instrumentation

Conversation

@overbalance
Copy link
Copy Markdown
Contributor

@overbalance overbalance commented Mar 7, 2026

Which problem is this PR solving?

When bundling with webpack, direct references to require in _warnOnPreloadedModules() cause webpack to analyze them as dependency expressions, leading to warnings or errors in bundled environments.

Short description of the changes

  • Access require via globalThis instead of directly, preventing webpack from treating it as a static dependency
  • Add an early return guard when require.resolve or require.cache are unavailable

Type of change

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

How Has This Been Tested?

  • Verified existing tests pass in the instrumentation package
  • Confirmed webpack builds no longer emit warnings for this require usage (located in separate PR)

Checklist:

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

@overbalance overbalance requested a review from a team as a code owner March 7, 2026 19:29
@overbalance overbalance added the browser Browser-specific additions or benefits label Mar 7, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.70%. Comparing base (356ddee) to head (a5cba39).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6481   +/-   ##
=======================================
  Coverage   95.70%   95.70%           
=======================================
  Files         364      364           
  Lines       11779    11779           
  Branches     2751     2751           
=======================================
  Hits        11273    11273           
  Misses        506      506           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@overbalance overbalance added this pull request to the merge queue Mar 9, 2026
Merged via the queue into open-telemetry:main with commit 124f09e Mar 9, 2026
27 checks passed
@overbalance overbalance deleted the overbalance/webpack-require-instrumentation branch March 9, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

browser Browser-specific additions or benefits

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants