Skip to content

Commit 77ae0dc

Browse files
committed
ref: Do not use build-time constant for SDK source at all ??
1 parent 8205969 commit 77ae0dc

File tree

5 files changed

+6
-37
lines changed

5 files changed

+6
-37
lines changed

dev-packages/rollup-utils/bundleHelpers.mjs

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
makeLicensePlugin,
1616
makeNodeResolvePlugin,
1717
makeRrwebBuildPlugin,
18-
makeSetSDKSourcePlugin,
1918
makeSucrasePlugin,
2019
makeTerserPlugin,
2120
} from './plugins/index.mjs';
@@ -51,6 +50,7 @@ export function makeBaseBundleConfig(options) {
5150
intro: () => {
5251
return 'exports = window.Sentry || {};';
5352
},
53+
banner: 'window.SENTRY_SDK_SOURCE = window.SENTRY_SDK_SOURCE || "cdn";',
5454
},
5555
context: 'window',
5656
plugins: [rrwebBuildPlugin, markAsBrowserBuildPlugin],
@@ -168,29 +168,28 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
168168
const includeDebuggingPlugin = makeIsDebugBuildPlugin(true);
169169
const stripDebuggingPlugin = makeIsDebugBuildPlugin(false);
170170
const terserPlugin = makeTerserPlugin();
171-
const setSdkSourcePlugin = makeSetSDKSourcePlugin('cdn');
172171

173172
// The additional options to use for each variant we're going to create.
174173
const variantSpecificConfigMap = {
175174
'.js': {
176175
output: {
177176
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.js`,
178177
},
179-
plugins: [includeDebuggingPlugin, setSdkSourcePlugin],
178+
plugins: [includeDebuggingPlugin],
180179
},
181180

182181
'.min.js': {
183182
output: {
184183
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.min.js`,
185184
},
186-
plugins: [stripDebuggingPlugin, setSdkSourcePlugin, terserPlugin],
185+
plugins: [stripDebuggingPlugin, terserPlugin],
187186
},
188187

189188
'.debug.min.js': {
190189
output: {
191190
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.debug.min.js`,
192191
},
193-
plugins: [includeDebuggingPlugin, setSdkSourcePlugin, terserPlugin],
192+
plugins: [includeDebuggingPlugin, terserPlugin],
194193
},
195194
};
196195

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

-9
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,6 @@ export function makeIsDebugBuildPlugin(includeDebugging) {
6060
});
6161
}
6262

63-
export function makeSetSDKSourcePlugin(sdkSource) {
64-
return replace({
65-
preventAssignment: false,
66-
values: {
67-
__SENTRY_SDK_SOURCE__: JSON.stringify(sdkSource),
68-
},
69-
});
70-
}
71-
7263
/**
7364
* Create a plugin to set the value of the `__SENTRY_BROWSER_BUNDLE__` magic string.
7465
*

packages/browser/src/client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
SeverityLevel,
1313
UserFeedback,
1414
} from '@sentry/types';
15-
import { getSDKSource, logger } from '@sentry/utils';
15+
import { logger } from '@sentry/utils';
1616

1717
import { DEBUG_BUILD } from './debug-build';
1818
import { eventFromException, eventFromMessage } from './eventbuilder';
@@ -57,7 +57,7 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
5757
parentSpanIsAlwaysRootSpan: true,
5858
...options,
5959
};
60-
const sdkSource = WINDOW.SENTRY_SDK_SOURCE || getSDKSource();
60+
const sdkSource = WINDOW.SENTRY_SDK_SOURCE || 'npm';
6161
applySdkMetadata(opts, 'browser', ['browser'], sdkSource);
6262

6363
super(opts);

packages/browser/test/index.test.ts

-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
inboundFiltersIntegration,
1414
lastEventId,
1515
} from '@sentry/core';
16-
import * as utils from '@sentry/utils';
1716

1817
import { setCurrentClient } from '../src';
1918
import {
@@ -382,17 +381,6 @@ describe('SentryBrowser initialization', () => {
382381
delete global.SENTRY_SDK_SOURCE;
383382
});
384383

385-
it('uses SDK source from global for package name', () => {
386-
const spy = vi.spyOn(utils, 'getSDKSource').mockReturnValue('cdn');
387-
init({ dsn });
388-
389-
const sdkData = getClient()?.getOptions()._metadata?.sdk || {};
390-
391-
expect(sdkData.packages?.[0]?.name).toBe('cdn:@sentry/browser');
392-
expect(utils.getSDKSource).toBeCalledTimes(1);
393-
spy.mockRestore();
394-
});
395-
396384
it('should set SDK data when instantiating a client directly', () => {
397385
const options = getDefaultBrowserClientOptions({ dsn });
398386
const client = new BrowserClient(options);

packages/utils/src/env.ts

-9
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
declare const __SENTRY_BROWSER_BUNDLE__: boolean | undefined;
1717

18-
declare const __SENTRY_SDK_SOURCE__: SdkSource | undefined;
19-
2018
export type SdkSource = 'npm' | 'cdn' | 'loader';
2119

2220
/**
@@ -27,10 +25,3 @@ export type SdkSource = 'npm' | 'cdn' | 'loader';
2725
export function isBrowserBundle(): boolean {
2826
return typeof __SENTRY_BROWSER_BUNDLE__ !== 'undefined' && !!__SENTRY_BROWSER_BUNDLE__;
2927
}
30-
31-
/**
32-
* Get source of SDK.
33-
*/
34-
export function getSDKSource(): SdkSource {
35-
return typeof __SENTRY_SDK_SOURCE__ !== 'undefined' ? __SENTRY_SDK_SOURCE__ : 'npm';
36-
}

0 commit comments

Comments
 (0)