File tree 4 files changed +16
-3
lines changed
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';
17
17
import { BREADCRUMB_INTEGRATION_ID } from './integrations/breadcrumbs' ;
18
18
import type { BrowserTransportOptions } from './transports/types' ;
19
19
20
- const sdkSource = getSDKSource ( ) ;
21
-
22
20
/**
23
21
* Configuration options for the Sentry Browser SDK.
24
22
* @see @sentry /types Options for more information.
@@ -44,6 +42,8 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
44
42
* @param options Configuration options for this SDK.
45
43
*/
46
44
public constructor ( options : BrowserClientOptions ) {
45
+ const sdkSource = WINDOW . SENTRY_SDK_SOURCE || getSDKSource ( ) ;
46
+
47
47
options . _metadata = options . _metadata || { } ;
48
48
options . _metadata . sdk = options . _metadata . sdk || {
49
49
name : 'sentry.javascript.browser' ,
Original file line number Diff line number Diff line change @@ -277,6 +277,16 @@ describe('SentryBrowser initialization', () => {
277
277
expect ( sdkData ?. version ) . toBe ( SDK_VERSION ) ;
278
278
} ) ;
279
279
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
+
280
290
it ( 'should set SDK data when instantiating a client directly' , ( ) => {
281
291
const options = getDefaultBrowserClientOptions ( { dsn } ) ;
282
292
const client = new BrowserClient ( options ) ;
Original file line number Diff line number Diff line change 15
15
16
16
declare const __SENTRY_BROWSER_BUNDLE__ : boolean | undefined ;
17
17
18
- type SdkSource = 'npm' | 'cdn' | 'loader' ;
18
+ export type SdkSource = 'npm' | 'cdn' | 'loader' ;
19
19
20
20
/**
21
21
* Figures out if we're building a browser bundle.
Original file line number Diff line number Diff line change 14
14
15
15
import type { Integration } from '@sentry/types' ;
16
16
17
+ import type { SdkSource } from './env' ;
18
+
17
19
/** Internal global with common properties and Sentry extensions */
18
20
export interface InternalGlobal {
19
21
navigator ?: { userAgent ?: string } ;
@@ -26,6 +28,7 @@ export interface InternalGlobal {
26
28
SENTRY_RELEASE ?: {
27
29
id ?: string ;
28
30
} ;
31
+ SENTRY_SDK_SOURCE ?: SdkSource ;
29
32
__SENTRY__ : {
30
33
globalEventProcessors : any ;
31
34
hub : any ;
You can’t perform that action at this time.
0 commit comments