4
4
Client ,
5
5
ClientOptions ,
6
6
DsnComponents ,
7
+ Envelope ,
7
8
Event ,
8
9
EventHint ,
9
10
Integration ,
@@ -30,7 +31,7 @@ import {
30
31
uuid4 ,
31
32
} from '@sentry/utils' ;
32
33
33
- import { getEnvelopeEndpointWithUrlEncodedAuth , initAPIDetails } from './api' ;
34
+ import { getEnvelopeEndpointWithUrlEncodedAuth } from './api' ;
34
35
import { IS_DEBUG_BUILD } from './flags' ;
35
36
import { IntegrationIndex , setupIntegrations } from './integration' ;
36
37
import { createEventEnvelope , createSessionEnvelope } from './request' ;
@@ -75,18 +76,14 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
75
76
/** The client Dsn, if specified in options. Without this Dsn, the SDK will be disabled. */
76
77
protected readonly _dsn ?: DsnComponents ;
77
78
79
+ protected readonly _transport ?: NewTransport | undefined ;
80
+
78
81
/** Array of used integrations. */
79
82
protected _integrations : IntegrationIndex = { } ;
80
83
81
84
/** Number of calls being processed */
82
85
protected _numProcessing : number = 0 ;
83
86
84
- /** Cached transport used internally. */
85
- protected _transport : NewTransport ;
86
-
87
- /** New v7 Transport that is initialized alongside the old one */
88
- protected _newTransport ?: NewTransport ;
89
-
90
87
/**
91
88
* Initializes this client instance.
92
89
*
@@ -96,18 +93,13 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
96
93
*/
97
94
protected constructor ( options : O ) {
98
95
this . _options = options ;
99
-
100
- let url ;
101
96
if ( options . dsn ) {
102
- this . _dsn = makeDsn ( options . dsn ) ;
103
- // TODO(v7): Figure out what to do with transport when dsn is not defined
104
- const api = initAPIDetails ( this . _dsn , options . _metadata , options . tunnel ) ;
105
- url = getEnvelopeEndpointWithUrlEncodedAuth ( api . dsn , api . tunnel ) ;
97
+ const dsn = makeDsn ( options . dsn ) ;
98
+ const url = getEnvelopeEndpointWithUrlEncodedAuth ( dsn , options . tunnel ) ;
99
+ this . _transport = options . transport ( { ...options . transportOptions , url } ) ;
106
100
} else {
107
101
IS_DEBUG_BUILD && logger . warn ( 'No DSN provided, client will not do anything.' ) ;
108
102
}
109
-
110
- this . _transport = options . transport ( { ...options . transportOptions , url } ) ;
111
103
}
112
104
113
105
/**
@@ -217,19 +209,22 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
217
209
/**
218
210
* @inheritDoc
219
211
*/
220
- public getTransport ( ) : Transport {
212
+ public getTransport ( ) : NewTransport | undefined {
221
213
return this . _transport ;
222
214
}
223
215
224
216
/**
225
217
* @inheritDoc
226
218
*/
227
219
public flush ( timeout ?: number ) : PromiseLike < boolean > {
228
- return this . _isClientDoneProcessing ( timeout ) . then ( clientFinished => {
229
- return this . getTransport ( )
230
- . close ( timeout )
231
- . then ( transportFlushed => clientFinished && transportFlushed ) ;
232
- } ) ;
220
+ const transport = this . _transport ;
221
+ if ( transport ) {
222
+ return this . _isClientDoneProcessing ( timeout ) . then ( clientFinished => {
223
+ return transport . flush ( timeout ) . then ( transportFlushed => clientFinished && transportFlushed ) ;
224
+ } ) ;
225
+ } else {
226
+ return resolvedSyncPromise ( true ) ;
227
+ }
233
228
}
234
229
235
230
/**
@@ -267,50 +262,32 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
267
262
* @inheritDoc
268
263
*/
269
264
public sendEvent ( event : Event ) : void {
270
- // TODO(v7): Remove the if-else
271
- if (
272
- this . _newTransport &&
273
- this . _options . dsn &&
274
- this . _options . _experiments &&
275
- this . _options . _experiments . newTransport
276
- ) {
277
- const api = initAPIDetails ( this . _options . dsn , this . _options . _metadata , this . _options . tunnel ) ;
278
- const env = createEventEnvelope ( event , api ) ;
279
- void this . _newTransport . send ( env ) . then ( null , reason => {
280
- IS_DEBUG_BUILD && logger . error ( 'Error while sending event:' , reason ) ;
281
- } ) ;
282
- } else {
283
- void this . _transport . sendEvent ( event ) . then ( null , reason => {
284
- IS_DEBUG_BUILD && logger . error ( 'Error while sending event:' , reason ) ;
285
- } ) ;
265
+ if ( this . _dsn ) {
266
+ const env = createEventEnvelope ( event , this . _dsn , this . _options . _metadata , this . _options . tunnel ) ;
267
+ this . sendEnvelope ( env ) ;
286
268
}
287
269
}
288
270
289
271
/**
290
272
* @inheritDoc
291
273
*/
292
274
public sendSession ( session : Session ) : void {
293
- if ( ! this . _transport . sendSession ) {
294
- IS_DEBUG_BUILD && logger . warn ( "Dropping session because custom transport doesn't implement sendSession" ) ;
295
- return ;
275
+ if ( this . _dsn ) {
276
+ const [ env ] = createSessionEnvelope ( session , this . _dsn , this . _options . _metadata , this . _options . tunnel ) ;
277
+ this . sendEnvelope ( env ) ;
296
278
}
279
+ }
297
280
298
- // TODO(v7): Remove the if-else
299
- if (
300
- this . _newTransport &&
301
- this . _options . dsn &&
302
- this . _options . _experiments &&
303
- this . _options . _experiments . newTransport
304
- ) {
305
- const api = initAPIDetails ( this . _options . dsn , this . _options . _metadata , this . _options . tunnel ) ;
306
- const [ env ] = createSessionEnvelope ( session , api ) ;
307
- void this . _newTransport . send ( env ) . then ( null , reason => {
308
- IS_DEBUG_BUILD && logger . error ( 'Error while sending session:' , reason ) ;
281
+ /**
282
+ * @inheritdoc
283
+ */
284
+ public sendEnvelope ( env : Envelope ) : void {
285
+ if ( this . _transport && this . _dsn ) {
286
+ this . _transport . send ( env ) . then ( null , reason => {
287
+ IS_DEBUG_BUILD && logger . error ( 'Error while sending event:' , reason ) ;
309
288
} ) ;
310
289
} else {
311
- void this . _transport . sendSession ( session ) . then ( null , reason => {
312
- IS_DEBUG_BUILD && logger . error ( 'Error while sending session:' , reason ) ;
313
- } ) ;
290
+ IS_DEBUG_BUILD && logger . error ( 'Transport disabled' ) ;
314
291
}
315
292
}
316
293
@@ -590,15 +567,15 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
590
567
protected _processEvent ( event : Event , hint ?: EventHint , scope ?: Scope ) : PromiseLike < Event > {
591
568
// eslint-disable-next-line @typescript-eslint/unbound-method
592
569
const { beforeSend, sampleRate } = this . getOptions ( ) ;
593
- const transport = this . getTransport ( ) ;
594
570
595
571
type RecordLostEvent = NonNullable < Transport [ 'recordLostEvent' ] > ;
596
572
type RecordLostEventParams = Parameters < RecordLostEvent > ;
597
573
598
- function recordLostEvent ( outcome : RecordLostEventParams [ 0 ] , category : RecordLostEventParams [ 1 ] ) : void {
599
- if ( transport . recordLostEvent ) {
600
- transport . recordLostEvent ( outcome , category ) ;
601
- }
574
+ function recordLostEvent ( _outcome : RecordLostEventParams [ 0 ] , _category : RecordLostEventParams [ 1 ] ) : void {
575
+ // no-op as new transports don't have client outcomes
576
+ // if (transport.recordLostEvent) {
577
+ // transport.recordLostEvent(outcome, category);
578
+ // }
602
579
}
603
580
604
581
if ( ! this . _isEnabled ( ) ) {
0 commit comments