Skip to content

Commit 3964548

Browse files
authored
fix(cdn): Fix SDK source for CDN bundles (#13475)
We used to replace `__SENTRY_SDK_SOURCE__` when we built `@sentry/utils`, which means that we could not overwrite it anymore for the CDN bundles, resulting in the SDK source being `npm` for the CDN bundles. This PR changes this so that this is correct now. Closes #13435
1 parent 977c508 commit 3964548

File tree

6 files changed

+51
-13
lines changed

6 files changed

+51
-13
lines changed

.size-limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module.exports = [
170170
path: createCDNPath('bundle.tracing.min.js'),
171171
gzip: false,
172172
brotli: false,
173-
limit: '111 KB',
173+
limit: '113 KB',
174174
},
175175
{
176176
name: 'CDN Bundle (incl. Tracing, Replay) - uncompressed',

dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/captureException/test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from '@playwright/test';
2+
import { SDK_VERSION } from '@sentry/browser';
23

34
import { sentryTest } from '../../../../utils/fixtures';
45
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';
@@ -11,3 +12,22 @@ sentryTest('captureException works', async ({ getLocalTestUrl, page }) => {
1112

1213
expect(eventData.message).toBe('Test exception');
1314
});
15+
16+
sentryTest('should capture correct SDK metadata', async ({ getLocalTestUrl, page }) => {
17+
const url = await getLocalTestUrl({ testDir: __dirname });
18+
const req = await waitForErrorRequestOnUrl(page, url);
19+
20+
const eventData = envelopeRequestParser(req);
21+
22+
expect(eventData.sdk).toMatchObject({
23+
name: 'sentry.javascript.browser',
24+
version: SDK_VERSION,
25+
integrations: expect.any(Object),
26+
packages: [
27+
{
28+
name: 'loader:@sentry/browser',
29+
version: SDK_VERSION,
30+
},
31+
],
32+
});
33+
});

dev-packages/browser-integration-tests/suites/public-api/captureException/simpleError/test.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { expect } from '@playwright/test';
2-
import type { Event } from '@sentry/types';
2+
import { SDK_VERSION } from '@sentry/browser';
33

44
import { sentryTest } from '../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
5+
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';
66

7-
sentryTest('should capture a simple error with message', async ({ getLocalTestPath, page }) => {
8-
const url = await getLocalTestPath({ testDir: __dirname });
9-
10-
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
7+
sentryTest('should capture a simple error with message', async ({ getLocalTestUrl, page }) => {
8+
const url = await getLocalTestUrl({ testDir: __dirname });
9+
const req = await waitForErrorRequestOnUrl(page, url);
10+
const eventData = envelopeRequestParser(req);
1111

1212
expect(eventData.exception?.values).toHaveLength(1);
1313
expect(eventData.exception?.values?.[0]).toMatchObject({
@@ -22,3 +22,23 @@ sentryTest('should capture a simple error with message', async ({ getLocalTestPa
2222
},
2323
});
2424
});
25+
26+
sentryTest('should capture correct SDK metadata', async ({ getLocalTestUrl, page }) => {
27+
const isCdn = (process.env.PW_BUNDLE || '').startsWith('bundle');
28+
29+
const url = await getLocalTestUrl({ testDir: __dirname });
30+
const req = await waitForErrorRequestOnUrl(page, url);
31+
const eventData = envelopeRequestParser(req);
32+
33+
expect(eventData.sdk).toEqual({
34+
name: 'sentry.javascript.browser',
35+
version: SDK_VERSION,
36+
integrations: expect.any(Object),
37+
packages: [
38+
{
39+
name: `${isCdn ? 'cdn' : 'npm'}:@sentry/browser`,
40+
version: SDK_VERSION,
41+
},
42+
],
43+
});
44+
});

dev-packages/rollup-utils/npmHelpers.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
makeImportMetaUrlReplacePlugin,
2020
makeNodeResolvePlugin,
2121
makeRrwebBuildPlugin,
22-
makeSetSDKSourcePlugin,
2322
makeSucrasePlugin,
2423
} from './plugins/index.mjs';
2524
import { makePackageNodeEsm } from './plugins/make-esm-plugin.mjs';
@@ -45,7 +44,6 @@ export function makeBaseNPMConfig(options = {}) {
4544
const importMetaUrlReplacePlugin = makeImportMetaUrlReplacePlugin();
4645
const cleanupPlugin = makeCleanupPlugin();
4746
const extractPolyfillsPlugin = makeExtractPolyfillsPlugin();
48-
const setSdkSourcePlugin = makeSetSDKSourcePlugin('npm');
4947
const rrwebBuildPlugin = makeRrwebBuildPlugin({
5048
excludeShadowDom: undefined,
5149
excludeIframe: undefined,
@@ -106,7 +104,6 @@ export function makeBaseNPMConfig(options = {}) {
106104

107105
plugins: [
108106
nodeResolvePlugin,
109-
setSdkSourcePlugin,
110107
sucrasePlugin,
111108
debugBuildStatementReplacePlugin,
112109
importMetaUrlReplacePlugin,

dev-packages/rollup-utils/plugins/bundlePlugins.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ export function makeIsDebugBuildPlugin(includeDebugging) {
6363
export function makeSetSDKSourcePlugin(sdkSource) {
6464
return replace({
6565
preventAssignment: false,
66+
delimiters: ['', ''],
6667
values: {
67-
__SENTRY_SDK_SOURCE__: JSON.stringify(sdkSource),
68+
'/* __SENTRY_SDK_SOURCE__ */': `return ${JSON.stringify(sdkSource)};`,
6869
},
6970
});
7071
}

packages/utils/src/env.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ export function isBrowserBundle(): boolean {
3030
* Get source of SDK.
3131
*/
3232
export function getSDKSource(): SdkSource {
33-
// @ts-expect-error __SENTRY_SDK_SOURCE__ is injected by rollup during build process
34-
return __SENTRY_SDK_SOURCE__;
33+
// This comment is used to identify this line in the CDN bundle build step and replace this with "return 'cdn';"
34+
/* __SENTRY_SDK_SOURCE__ */ return 'npm';
3535
}

0 commit comments

Comments
 (0)