fix(sdk-trace-base): avoid webpack CommonJS self-reference - #6982
fix(sdk-trace-base): avoid webpack CommonJS self-reference#6982sansynx wants to merge 4 commits into
Conversation
Signed-off-by: sanath <sanathrshs@gmail.com>
|
|
|
Welcome, contributor! Thank you for your contribution to opentelemetry-js. Important reminders:
|
There was a problem hiding this comment.
Pull request overview
This PR addresses a webpack production bundling crash triggered when an ESM named import is resolved through a CommonJS main entry, by ensuring sdk-trace-base reads span-limit defaults from local bindings (avoiding exports.* self-references after TypeScript emit and webpack tree-shaking). It also adds a bundler regression fixture and documents the change.
Changes:
- Refactors
sdk-trace-basedefault span-limit constants to retain local bindings before exporting. - Updates the Node/webpack-5 bundler fixture to resolve via
main(CommonJS) and exercises@opentelemetry/sdk-node’s publicNodeSDKentry. - Adds an Unreleased changelog entry for the fix.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/opentelemetry-sdk-trace-base/src/utility.ts | Keeps default limit constants as local bindings and exports them, preventing webpack self-reference failures. |
| bundler-tests/node/webpack-5/webpack.config.mjs | Forces resolve.mainFields: ['main'] to reproduce CommonJS-entry bundling behavior in production mode. |
| bundler-tests/node/webpack-5/src/index.js | Imports and instantiates NodeSDK from the public entry to cover the reported regression scenario. |
| bundler-tests/node/webpack-5/package.json | Adds the local @opentelemetry/sdk-node dependency for the new bundling fixture. |
| CHANGELOG.md | Documents the fix in the Unreleased bug fixes section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Pull request dashboard statusWaiting on reviewers · refreshed 2026-08-21 22:12 UTC Review the latest changes. Also blocked by: Merge conflicts. Status above doesn't look right?
|
overbalance
left a comment
There was a problem hiding this comment.
I recommend creating a new test suite instead of changing this one so the old bundling behavior is still covered.
Signed-off-by: sanath <sanathrshs@gmail.com>
|
@overbalance Thanks for the suggestion, I split the NodeSDK/CommonJS regression into a new Both suites pass independently |
|
Hi @overbalance @sansynx, is there an ETA for getting this merged? I have several consumers of a library I own facing the build error caused by the issue when using Webpack. Thanks! |
|
@iivvaannxx it's ready, just need @overbalance approval for this to get merged! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6982 +/- ##
=======================================
Coverage 95.09% 95.09%
=======================================
Files 409 409
Lines 14259 14260 +1
Branches 3269 3269
=======================================
+ Hits 13559 13560 +1
Misses 700 700
🚀 New features to boost your workflow:
|
overbalance
left a comment
There was a problem hiding this comment.
That's not entirely true 🙂 I'm a Browser maintainer so I check code that affects the client. A JS core approver still needs to look.
If you would, please add a brief comment above these constants explaining the declaration/export split is intentional. Like "TS gen CJS emit rewrites internal reads of export const to exports.*, which trips webpack’s self-reference handling when the export is tree-shaken unused (#6981, webpack/webpack#21619)
And thank you for pointing this out. I suspect the project has more instances of the same issue that will need investigation.
|
|
||
| ### :bug: Bug Fixes | ||
|
|
||
| * fix(sdk-trace-base): avoid a Webpack self-reference error in CommonJS output #6981 @sansynx |
There was a problem hiding this comment.
Please update the link to match the others.
There was a problem hiding this comment.
Thanks for pointing that out — I’ve updated the entry to use the same linked issue format as the surrounding changelog items: #6981
Link the reported issue in the changelog and document why the local constant declarations must stay separate from their exports Signed-off-by: sanath <sanathrshs@gmail.com>
|
Thanks for the follow-up — I’ve added a short note above the constants explaining why they stay local and are exported separately I also kept the sdk-node regression coverage in its own webpack suite, so the existing bundling behavior remains covered The focused trace-base tests pass (22 tests), along with the trace-base compile, lint and formatting checks, changelog markdown lint, and the new Node/Webpack 5 bundle check I used an AI coding assistant to help with the edit, then reviewed the diff and ran the checks myself |
Summary
NodeSDKCommonJS entryRoot cause
TypeScript emitted internal reads of exported constants as
exports.*. When Webpack tree-shook an ESM named import resolved through the CommonJSmainentry, it treated that as an invalid self-reference.Validation
npm exec -- tsc --build packages/opentelemetry-sdk-trace-base/tsconfig.json --pretty falsenpm --prefix packages/opentelemetry-sdk-trace-base run lintnpm exec -- mocha @testFiles(21 passing focused trace-base tests)node test-bundle.mjsinbundler-tests/node/webpack-5npm exec -- prettier --check ...npm exec -- markdownlint-cli2 CHANGELOG.mdFixes #6981