Skip to content

Commit

Permalink
ref: Do not use build-time constant for SDK source at all ??
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Aug 27, 2024
1 parent 8205969 commit 77ae0dc
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 37 deletions.
9 changes: 4 additions & 5 deletions dev-packages/rollup-utils/bundleHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
makeLicensePlugin,
makeNodeResolvePlugin,
makeRrwebBuildPlugin,
makeSetSDKSourcePlugin,
makeSucrasePlugin,
makeTerserPlugin,
} from './plugins/index.mjs';
Expand Down Expand Up @@ -51,6 +50,7 @@ export function makeBaseBundleConfig(options) {
intro: () => {
return 'exports = window.Sentry || {};';
},
banner: 'window.SENTRY_SDK_SOURCE = window.SENTRY_SDK_SOURCE || "cdn";',
},
context: 'window',
plugins: [rrwebBuildPlugin, markAsBrowserBuildPlugin],
Expand Down Expand Up @@ -168,29 +168,28 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
const includeDebuggingPlugin = makeIsDebugBuildPlugin(true);
const stripDebuggingPlugin = makeIsDebugBuildPlugin(false);
const terserPlugin = makeTerserPlugin();
const setSdkSourcePlugin = makeSetSDKSourcePlugin('cdn');

// The additional options to use for each variant we're going to create.
const variantSpecificConfigMap = {
'.js': {
output: {
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.js`,
},
plugins: [includeDebuggingPlugin, setSdkSourcePlugin],
plugins: [includeDebuggingPlugin],
},

'.min.js': {
output: {
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.min.js`,
},
plugins: [stripDebuggingPlugin, setSdkSourcePlugin, terserPlugin],
plugins: [stripDebuggingPlugin, terserPlugin],
},

'.debug.min.js': {
output: {
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.debug.min.js`,
},
plugins: [includeDebuggingPlugin, setSdkSourcePlugin, terserPlugin],
plugins: [includeDebuggingPlugin, terserPlugin],
},
};

Expand Down
9 changes: 0 additions & 9 deletions dev-packages/rollup-utils/plugins/bundlePlugins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ export function makeIsDebugBuildPlugin(includeDebugging) {
});
}

export function makeSetSDKSourcePlugin(sdkSource) {
return replace({
preventAssignment: false,
values: {
__SENTRY_SDK_SOURCE__: JSON.stringify(sdkSource),
},
});
}

/**
* Create a plugin to set the value of the `__SENTRY_BROWSER_BUNDLE__` magic string.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
SeverityLevel,
UserFeedback,
} from '@sentry/types';
import { getSDKSource, logger } from '@sentry/utils';
import { logger } from '@sentry/utils';

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

super(opts);
Expand Down
12 changes: 0 additions & 12 deletions packages/browser/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
inboundFiltersIntegration,
lastEventId,
} from '@sentry/core';
import * as utils from '@sentry/utils';

import { setCurrentClient } from '../src';
import {
Expand Down Expand Up @@ -382,17 +381,6 @@ describe('SentryBrowser initialization', () => {
delete global.SENTRY_SDK_SOURCE;
});

it('uses SDK source from global for package name', () => {
const spy = vi.spyOn(utils, 'getSDKSource').mockReturnValue('cdn');
init({ dsn });

const sdkData = getClient()?.getOptions()._metadata?.sdk || {};

expect(sdkData.packages?.[0]?.name).toBe('cdn:@sentry/browser');
expect(utils.getSDKSource).toBeCalledTimes(1);
spy.mockRestore();
});

it('should set SDK data when instantiating a client directly', () => {
const options = getDefaultBrowserClientOptions({ dsn });
const client = new BrowserClient(options);
Expand Down
9 changes: 0 additions & 9 deletions packages/utils/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

declare const __SENTRY_BROWSER_BUNDLE__: boolean | undefined;

declare const __SENTRY_SDK_SOURCE__: SdkSource | undefined;

export type SdkSource = 'npm' | 'cdn' | 'loader';

/**
Expand All @@ -27,10 +25,3 @@ export type SdkSource = 'npm' | 'cdn' | 'loader';
export function isBrowserBundle(): boolean {
return typeof __SENTRY_BROWSER_BUNDLE__ !== 'undefined' && !!__SENTRY_BROWSER_BUNDLE__;
}

/**
* Get source of SDK.
*/
export function getSDKSource(): SdkSource {
return typeof __SENTRY_SDK_SOURCE__ !== 'undefined' ? __SENTRY_SDK_SOURCE__ : 'npm';
}

0 comments on commit 77ae0dc

Please sign in to comment.