File tree Expand file tree Collapse file tree 4 files changed +16
-3
lines changed Expand file tree Collapse file tree 4 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,6 @@ import type { Breadcrumbs } from './integrations';
1717import { BREADCRUMB_INTEGRATION_ID } from './integrations/breadcrumbs' ;
1818import 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' ,
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff line change 1515
1616declare const __SENTRY_BROWSER_BUNDLE__ : boolean | undefined ;
1717
18- type SdkSource = 'npm' | 'cdn' | 'loader' ;
18+ export type SdkSource = 'npm' | 'cdn' | 'loader' ;
1919
2020declare const __SENTRY_SDK_SOURCE__ : SdkSource | undefined ;
2121
Original file line number Diff line number Diff line change 1414
1515import type { Integration } from '@sentry/types' ;
1616
17+ import type { SdkSource } from './env' ;
18+
1719/** Internal global with common properties and Sentry extensions */
1820export 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 ;
You can’t perform that action at this time.
0 commit comments