Skip to content

Commit 931a81e

Browse files
committed
set from window
1 parent 3d30048 commit 931a81e

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

packages/browser/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import type { Breadcrumbs } from './integrations';
1717
import { BREADCRUMB_INTEGRATION_ID } from './integrations/breadcrumbs';
1818
import type { BrowserTransportOptions } from './transports/types';
1919

20-
const sdkSource = getSDKSource();
21-
2220
/**
2321
* Configuration options for the Sentry Browser SDK.
2422
* @see @sentry/types Options for more information.
@@ -44,6 +42,8 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
4442
* @param options Configuration options for this SDK.
4543
*/
4644
public constructor(options: BrowserClientOptions) {
45+
const sdkSource = WINDOW.SENTRY_SDK_SOURCE || getSDKSource();
46+
4747
options._metadata = options._metadata || {};
4848
options._metadata.sdk = options._metadata.sdk || {
4949
name: 'sentry.javascript.browser',

packages/browser/test/unit/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ describe('SentryBrowser initialization', () => {
277277
expect(sdkData?.version).toBe(SDK_VERSION);
278278
});
279279

280+
it('uses SDK source from window', () => {
281+
global.SENTRY_SDK_SOURCE = 'loader';
282+
init({ dsn });
283+
284+
const sdkData = (getCurrentHub().getClient() as any).getOptions()._metadata.sdk;
285+
286+
expect(sdkData?.packages[0].name).toBe('loader:@sentry/browser');
287+
delete global.SENTRY_SDK_SOURCE;
288+
});
289+
280290
it('should set SDK data when instantiating a client directly', () => {
281291
const options = getDefaultBrowserClientOptions({ dsn });
282292
const client = new BrowserClient(options);

packages/utils/src/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
declare const __SENTRY_BROWSER_BUNDLE__: boolean | undefined;
1717

18-
type SdkSource = 'npm' | 'cdn' | 'loader';
18+
export type SdkSource = 'npm' | 'cdn' | 'loader';
1919

2020
/**
2121
* Figures out if we're building a browser bundle.

packages/utils/src/worldwide.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import type { Integration } from '@sentry/types';
1616

17+
import type { SdkSource } from './env';
18+
1719
/** Internal global with common properties and Sentry extensions */
1820
export interface InternalGlobal {
1921
navigator?: { userAgent?: string };
@@ -26,6 +28,7 @@ export interface InternalGlobal {
2628
SENTRY_RELEASE?: {
2729
id?: string;
2830
};
31+
SENTRY_SDK_SOURCE?: SdkSource;
2932
__SENTRY__: {
3033
globalEventProcessors: any;
3134
hub: any;

0 commit comments

Comments
 (0)