1
- import { BaseClient , Scope , SDK_VERSION } from '@sentry/core' ;
2
- import { Event , EventHint } from '@sentry/types' ;
3
- import { getGlobalObject , logger } from '@sentry/utils' ;
1
+ import { BaseClient , getEnvelopeEndpointWithUrlEncodedAuth , initAPIDetails , Scope , SDK_VERSION } from '@sentry/core' ;
2
+ import { Event , EventHint , Severity , Transport , TransportOptions } from '@sentry/types' ;
3
+ import { getGlobalObject , logger , supportsFetch } from '@sentry/utils' ;
4
4
5
5
import { BrowserBackend , BrowserOptions } from './backend' ;
6
+ import { eventFromException , eventFromMessage } from './eventbuilder' ;
6
7
import { IS_DEBUG_BUILD } from './flags' ;
7
8
import { injectReportDialog , ReportDialogOptions } from './helpers' ;
8
9
import { Breadcrumbs } from './integrations' ;
10
+ import { FetchTransport , makeNewFetchTransport , makeNewXHRTransport , XHRTransport } from './transports' ;
9
11
10
12
/**
11
13
* The Sentry Browser SDK Client.
12
14
*
13
15
* @see BrowserOptions for documentation on configuration options.
14
16
* @see SentryClient for usage documentation.
17
+ * TODO: remove BrowserBackend
15
18
*/
16
19
export class BrowserClient extends BaseClient < BrowserBackend , BrowserOptions > {
17
20
/**
@@ -32,6 +35,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
32
35
version : SDK_VERSION ,
33
36
} ;
34
37
38
+ // TODO: remove BrowserBackend param
35
39
super ( BrowserBackend , options ) ;
36
40
}
37
41
@@ -58,6 +62,20 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
58
62
} ) ;
59
63
}
60
64
65
+ /**
66
+ * @inheritDoc
67
+ */
68
+ public eventFromException ( exception : unknown , hint ?: EventHint ) : PromiseLike < Event > {
69
+ return eventFromException ( exception , hint , this . _options . attachStacktrace ) ;
70
+ }
71
+
72
+ /**
73
+ * @inheritDoc
74
+ */
75
+ public eventFromMessage ( message : string , level : Severity = Severity . Info , hint ?: EventHint ) : PromiseLike < Event > {
76
+ return eventFromMessage ( message , level , hint , this . _options . attachStacktrace ) ;
77
+ }
78
+
61
79
/**
62
80
* @inheritDoc
63
81
*/
@@ -76,4 +94,40 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
76
94
}
77
95
super . _sendEvent ( event ) ;
78
96
}
97
+
98
+ /**
99
+ * @inheritDoc
100
+ */
101
+ protected _setupTransport ( ) : Transport {
102
+ if ( ! this . _options . dsn ) {
103
+ // We return the noop transport here in case there is no Dsn.
104
+ return super . _setupTransport ( ) ;
105
+ }
106
+
107
+ const transportOptions : TransportOptions = {
108
+ ...this . _options . transportOptions ,
109
+ dsn : this . _options . dsn ,
110
+ tunnel : this . _options . tunnel ,
111
+ sendClientReports : this . _options . sendClientReports ,
112
+ _metadata : this . _options . _metadata ,
113
+ } ;
114
+
115
+ const api = initAPIDetails ( transportOptions . dsn , transportOptions . _metadata , transportOptions . tunnel ) ;
116
+ const url = getEnvelopeEndpointWithUrlEncodedAuth ( api . dsn , api . tunnel ) ;
117
+
118
+ if ( this . _options . transport ) {
119
+ return new this . _options . transport ( transportOptions ) ;
120
+ }
121
+ if ( supportsFetch ( ) ) {
122
+ const requestOptions : RequestInit = { ...transportOptions . fetchParameters } ;
123
+ this . _newTransport = makeNewFetchTransport ( { requestOptions, url } ) ;
124
+ return new FetchTransport ( transportOptions ) ;
125
+ }
126
+
127
+ this . _newTransport = makeNewXHRTransport ( {
128
+ url,
129
+ headers : transportOptions . headers ,
130
+ } ) ;
131
+ return new XHRTransport ( transportOptions ) ;
132
+ }
79
133
}
0 commit comments