Skip to content

Commit 83bc92a

Browse files
committed
Make baseclient use new transport
1 parent 6df9533 commit 83bc92a

File tree

1 file changed

+18
-52
lines changed

1 file changed

+18
-52
lines changed

packages/core/src/baseclient.ts

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
EventHint,
88
Integration,
99
IntegrationClass,
10+
NewTransport,
1011
Options,
1112
Severity,
1213
SeverityLevel,
@@ -29,11 +30,10 @@ import {
2930
uuid4,
3031
} from '@sentry/utils';
3132

32-
import { APIDetails, initAPIDetails } from './api';
33+
import { initAPIDetails } from './api';
3334
import { IS_DEBUG_BUILD } from './flags';
3435
import { IntegrationIndex, setupIntegrations } from './integration';
3536
import { createEventEnvelope, createSessionEnvelope } from './request';
36-
import { NewTransport } from './transports/base';
3737

3838
const ALREADY_SEEN_ERROR = "Not capturing exception because it's already been captured.";
3939

@@ -82,10 +82,7 @@ export abstract class BaseClient<O extends Options> implements Client<O> {
8282
protected _numProcessing: number = 0;
8383

8484
/** Cached transport used internally. */
85-
protected _transport: Transport;
86-
87-
/** New v7 Transport that is initialized alongside the old one */
88-
protected _newTransport?: NewTransport;
85+
protected _transport: NewTransport;
8986

9087
/**
9188
* Initializes this client instance.
@@ -94,7 +91,7 @@ export abstract class BaseClient<O extends Options> implements Client<O> {
9491
* @param transport The (old) Transport instance for the client to use (TODO(v7): remove)
9592
* @param newTransport The NewTransport instance for the client to use
9693
*/
97-
protected constructor(options: O, transport: Transport, newTransport?: NewTransport) {
94+
protected constructor(options: O, transport: NewTransport) {
9895
this._options = options;
9996

10097
if (options.dsn) {
@@ -103,16 +100,7 @@ export abstract class BaseClient<O extends Options> implements Client<O> {
103100
IS_DEBUG_BUILD && logger.warn('No DSN provided, client will not do anything.');
104101
}
105102

106-
// TODO(v7): remove old transport
107103
this._transport = transport;
108-
this._newTransport = newTransport;
109-
110-
// TODO(v7): refactor this to keep metadata/api outside of transport. This hack is used to
111-
// satisfy tests until we move to NewTransport where we have to revisit this.
112-
(this._transport as unknown as { _api: Partial<APIDetails> })._api = {
113-
...((this._transport as unknown as { _api: Partial<APIDetails> })._api || {}),
114-
metadata: options._metadata || {},
115-
};
116104
}
117105

118106
/**
@@ -222,7 +210,7 @@ export abstract class BaseClient<O extends Options> implements Client<O> {
222210
/**
223211
* @inheritDoc
224212
*/
225-
public getTransport(): Transport {
213+
public getTransport(): NewTransport {
226214
return this._transport;
227215
}
228216

@@ -232,7 +220,7 @@ export abstract class BaseClient<O extends Options> implements Client<O> {
232220
public flush(timeout?: number): PromiseLike<boolean> {
233221
return this._isClientDoneProcessing(timeout).then(clientFinished => {
234222
return this.getTransport()
235-
.close(timeout)
223+
.flush(timeout)
236224
.then(transportFlushed => clientFinished && transportFlushed);
237225
});
238226
}
@@ -272,20 +260,11 @@ export abstract class BaseClient<O extends Options> implements Client<O> {
272260
* @inheritDoc
273261
*/
274262
public sendEvent(event: Event): void {
275-
// TODO(v7): Remove the if-else
276-
if (
277-
this._newTransport &&
278-
this._options.dsn &&
279-
this._options._experiments &&
280-
this._options._experiments.newTransport
281-
) {
263+
if (this._options.dsn) {
282264
const api = initAPIDetails(this._options.dsn, this._options._metadata, this._options.tunnel);
283265
const env = createEventEnvelope(event, api);
284-
void this._newTransport.send(env).then(null, reason => {
285-
IS_DEBUG_BUILD && logger.error('Error while sending event:', reason);
286-
});
287-
} else {
288-
void this._transport.sendEvent(event).then(null, reason => {
266+
// TODO: Adjust client reports based on transport response
267+
void this._transport.send(env).then(null, reason => {
289268
IS_DEBUG_BUILD && logger.error('Error while sending event:', reason);
290269
});
291270
}
@@ -295,25 +274,11 @@ export abstract class BaseClient<O extends Options> implements Client<O> {
295274
* @inheritDoc
296275
*/
297276
public sendSession(session: Session): void {
298-
if (!this._transport.sendSession) {
299-
IS_DEBUG_BUILD && logger.warn("Dropping session because custom transport doesn't implement sendSession");
300-
return;
301-
}
302-
303-
// TODO(v7): Remove the if-else
304-
if (
305-
this._newTransport &&
306-
this._options.dsn &&
307-
this._options._experiments &&
308-
this._options._experiments.newTransport
309-
) {
277+
if (this._options.dsn) {
310278
const api = initAPIDetails(this._options.dsn, this._options._metadata, this._options.tunnel);
311279
const [env] = createSessionEnvelope(session, api);
312-
void this._newTransport.send(env).then(null, reason => {
313-
IS_DEBUG_BUILD && logger.error('Error while sending session:', reason);
314-
});
315-
} else {
316-
void this._transport.sendSession(session).then(null, reason => {
280+
// TODO: Adjust client reports based on transport response
281+
void this._transport.send(env).then(null, reason => {
317282
IS_DEBUG_BUILD && logger.error('Error while sending session:', reason);
318283
});
319284
}
@@ -595,15 +560,16 @@ export abstract class BaseClient<O extends Options> implements Client<O> {
595560
protected _processEvent(event: Event, hint?: EventHint, scope?: Scope): PromiseLike<Event> {
596561
// eslint-disable-next-line @typescript-eslint/unbound-method
597562
const { beforeSend, sampleRate } = this.getOptions();
598-
const transport = this.getTransport();
563+
// const transport = this.getTransport();
599564

600565
type RecordLostEvent = NonNullable<Transport['recordLostEvent']>;
601566
type RecordLostEventParams = Parameters<RecordLostEvent>;
602567

603-
function recordLostEvent(outcome: RecordLostEventParams[0], category: RecordLostEventParams[1]): void {
604-
if (transport.recordLostEvent) {
605-
transport.recordLostEvent(outcome, category);
606-
}
568+
// TODO(v7): Make client reports work with new transports
569+
function recordLostEvent(_outcome: RecordLostEventParams[0], _category: RecordLostEventParams[1]): void {
570+
// if (transport.recordLostEvent) {
571+
// transport.recordLostEvent(outcome, category);
572+
// }
607573
}
608574

609575
if (!this._isEnabled()) {

0 commit comments

Comments
 (0)