-
Notifications
You must be signed in to change notification settings - Fork 51
fix(esbuild): fix debug ID injection when moduleMetadata or applicationKey is set
#828
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
Merged
logaretm
merged 8 commits into
main
from
awad/bundler-91-esbuild-modulemetadata-breaks-debugid-injection
Dec 29, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
77f1afa
tests: added tests to confirm bug
logaretm ea9bd01
fix(esbuild): ensure debug IDs are injected alongside moduleMetadata
logaretm 9f90d82
fix: linting and enable es6
logaretm 8f92c31
chore: comments
logaretm 65c3e76
test: added applicationKey setting tests
logaretm 0ec8c82
fix(esbuild): strip query strings from importer paths in metadata pro…
logaretm eedca87
fix(esbuild): clear state from previous builds for watch mode and tests
logaretm a787f4f
fix(esbuild): clear stale metadata entries during build state reset
logaretm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ module.exports = { | |
| }, | ||
| env: { | ||
| node: true, | ||
| es6: true, | ||
| }, | ||
| settings: { | ||
| jest: { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ration-tests/fixtures/application-key-with-debug-id/application-key-with-debug-id.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* eslint-disable jest/no-standalone-expect */ | ||
| /* eslint-disable jest/expect-expect */ | ||
| import { execSync } from "child_process"; | ||
| import path from "path"; | ||
| import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; | ||
|
|
||
| interface BundleOutput { | ||
| debugIds: Record<string, string> | undefined; | ||
| metadata: Record<string, unknown> | undefined; | ||
| } | ||
|
|
||
| function checkBundle(bundlePath: string): void { | ||
| const output = execSync(`node ${bundlePath}`, { encoding: "utf-8" }); | ||
| const result = JSON.parse(output) as BundleOutput; | ||
|
|
||
| // Check that debug IDs are present | ||
| expect(result.debugIds).toBeDefined(); | ||
| const debugIds = Object.values(result.debugIds ?? {}); | ||
| expect(debugIds.length).toBeGreaterThan(0); | ||
| // Verify debug ID format (UUID v4) | ||
| expect(debugIds).toContainEqual( | ||
| expect.stringMatching(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/) | ||
| ); | ||
| // The key should be a stack trace | ||
| expect(Object.keys(result.debugIds ?? {})[0]).toContain("Error"); | ||
|
|
||
| // Check that applicationKey metadata is present | ||
| expect(result.metadata).toBeDefined(); | ||
| const metadataValues = Object.values(result.metadata ?? {}); | ||
| expect(metadataValues).toHaveLength(1); | ||
| // applicationKey sets a special key in the metadata | ||
| expect(metadataValues[0]).toEqual({ "_sentryBundlerPluginAppKey:my-app-key": true }); | ||
| // The key should be a stack trace | ||
| expect(Object.keys(result.metadata ?? {})[0]).toContain("Error"); | ||
| } | ||
|
|
||
| describe("applicationKey with debug ID injection", () => { | ||
| testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => { | ||
| checkBundle(path.join(__dirname, "out", "webpack4", "bundle.js")); | ||
| }); | ||
logaretm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test("webpack 5 bundle", () => { | ||
| checkBundle(path.join(__dirname, "out", "webpack5", "bundle.js")); | ||
| }); | ||
|
|
||
| test("esbuild bundle", () => { | ||
| checkBundle(path.join(__dirname, "out", "esbuild", "bundle.js")); | ||
| }); | ||
|
|
||
| test("rollup bundle", () => { | ||
| checkBundle(path.join(__dirname, "out", "rollup", "bundle.js")); | ||
| }); | ||
|
|
||
| test("vite bundle", () => { | ||
| checkBundle(path.join(__dirname, "out", "vite", "bundle.js")); | ||
| }); | ||
| }); | ||
9 changes: 9 additions & 0 deletions
9
packages/integration-tests/fixtures/application-key-with-debug-id/input/bundle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */ | ||
| // Output both debug IDs and metadata to verify applicationKey works with debug ID injection | ||
| // eslint-disable-next-line no-console | ||
| console.log( | ||
| JSON.stringify({ | ||
| debugIds: global._sentryDebugIds, | ||
| metadata: global._sentryModuleMetadata, | ||
| }) | ||
| ); |
18 changes: 18 additions & 0 deletions
18
packages/integration-tests/fixtures/application-key-with-debug-id/setup.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as path from "path"; | ||
| import { createCjsBundles } from "../../utils/create-cjs-bundles"; | ||
|
|
||
| const outputDir = path.resolve(__dirname, "out"); | ||
|
|
||
| createCjsBundles( | ||
| { | ||
| bundle: path.resolve(__dirname, "input", "bundle.js"), | ||
| }, | ||
| outputDir, | ||
| { | ||
| // Enable applicationKey AND debug ID injection (sourcemaps enabled by default) | ||
| applicationKey: "my-app-key", | ||
| telemetry: false, | ||
| release: { name: "test-release", create: false }, | ||
| }, | ||
| ["webpack4", "webpack5", "esbuild", "rollup", "vite"] | ||
| ); |
9 changes: 9 additions & 0 deletions
9
packages/integration-tests/fixtures/metadata-with-debug-id/input/bundle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */ | ||
| // Output both debug IDs and metadata to verify both features work together | ||
| // eslint-disable-next-line no-console | ||
| console.log( | ||
| JSON.stringify({ | ||
| debugIds: global._sentryDebugIds, | ||
| metadata: global._sentryModuleMetadata, | ||
| }) | ||
| ); |
56 changes: 56 additions & 0 deletions
56
packages/integration-tests/fixtures/metadata-with-debug-id/metadata-with-debug-id.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* eslint-disable jest/no-standalone-expect */ | ||
| /* eslint-disable jest/expect-expect */ | ||
| import { execSync } from "child_process"; | ||
| import path from "path"; | ||
| import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; | ||
|
|
||
| interface BundleOutput { | ||
| debugIds: Record<string, string> | undefined; | ||
| metadata: Record<string, unknown> | undefined; | ||
| } | ||
|
|
||
| function checkBundle(bundlePath: string): void { | ||
| const output = execSync(`node ${bundlePath}`, { encoding: "utf-8" }); | ||
| const result = JSON.parse(output) as BundleOutput; | ||
|
|
||
| // Check that debug IDs are present | ||
| expect(result.debugIds).toBeDefined(); | ||
| const debugIds = Object.values(result.debugIds ?? {}); | ||
| expect(debugIds.length).toBeGreaterThan(0); | ||
| // Verify debug ID format (UUID v4) | ||
| expect(debugIds).toContainEqual( | ||
| expect.stringMatching(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/) | ||
| ); | ||
| // The key should be a stack trace | ||
| expect(Object.keys(result.debugIds ?? {})[0]).toContain("Error"); | ||
|
|
||
| // Check that metadata is present | ||
| expect(result.metadata).toBeDefined(); | ||
| const metadataValues = Object.values(result.metadata ?? {}); | ||
| expect(metadataValues).toHaveLength(1); | ||
| expect(metadataValues).toEqual([{ team: "frontend" }]); | ||
| // The key should be a stack trace | ||
| expect(Object.keys(result.metadata ?? {})[0]).toContain("Error"); | ||
| } | ||
|
|
||
| describe("metadata with debug ID injection", () => { | ||
| testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => { | ||
| checkBundle(path.join(__dirname, "out", "webpack4", "bundle.js")); | ||
| }); | ||
logaretm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test("webpack 5 bundle", () => { | ||
| checkBundle(path.join(__dirname, "out", "webpack5", "bundle.js")); | ||
| }); | ||
|
|
||
| test("esbuild bundle", () => { | ||
| checkBundle(path.join(__dirname, "out", "esbuild", "bundle.js")); | ||
| }); | ||
|
|
||
| test("rollup bundle", () => { | ||
| checkBundle(path.join(__dirname, "out", "rollup", "bundle.js")); | ||
| }); | ||
|
|
||
| test("vite bundle", () => { | ||
| checkBundle(path.join(__dirname, "out", "vite", "bundle.js")); | ||
| }); | ||
| }); | ||
18 changes: 18 additions & 0 deletions
18
packages/integration-tests/fixtures/metadata-with-debug-id/setup.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as path from "path"; | ||
| import { createCjsBundles } from "../../utils/create-cjs-bundles"; | ||
|
|
||
| const outputDir = path.resolve(__dirname, "out"); | ||
|
|
||
| createCjsBundles( | ||
| { | ||
| bundle: path.resolve(__dirname, "input", "bundle.js"), | ||
| }, | ||
| outputDir, | ||
| { | ||
| // Enable both moduleMetadata AND debug ID injection (sourcemaps enabled by default) | ||
| moduleMetadata: { team: "frontend" }, | ||
| telemetry: false, | ||
| release: { name: "test-release", create: false }, | ||
| }, | ||
| ["webpack4", "webpack5", "esbuild", "rollup", "vite"] | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.