Skip to content

Commit d759f7a

Browse files
committed
delete setupTransport(), cleanup TODOs, add doc
1 parent 57a5158 commit d759f7a

File tree

7 files changed

+20
-123
lines changed

7 files changed

+20
-123
lines changed

packages/browser/src/client.ts

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
import {
2-
BaseClient,
3-
getEnvelopeEndpointWithUrlEncodedAuth,
4-
initAPIDetails,
5-
NewTransport,
6-
Scope,
7-
SDK_VERSION,
8-
} from '@sentry/core';
9-
import { Event, EventHint, Options, Severity, Transport, TransportOptions } from '@sentry/types';
10-
import { getGlobalObject, logger, stackParserFromOptions, supportsFetch } from '@sentry/utils';
1+
import { BaseClient, NewTransport, Scope, SDK_VERSION } from '@sentry/core';
2+
import { Event, EventHint, Options, Severity, Transport } from '@sentry/types';
3+
import { getGlobalObject, logger, stackParserFromOptions } from '@sentry/utils';
114

125
import { eventFromException, eventFromMessage } from './eventbuilder';
136
import { IS_DEBUG_BUILD } from './flags';
147
import { injectReportDialog, ReportDialogOptions } from './helpers';
158
import { Breadcrumbs } from './integrations';
16-
import { FetchTransport, makeNewFetchTransport, makeNewXHRTransport, XHRTransport } from './transports';
179

1810
/**
1911
* Configuration options for the Sentry Browser SDK.
@@ -124,40 +116,4 @@ export class BrowserClient extends BaseClient<BrowserOptions> {
124116
}
125117
super._sendEvent(event);
126118
}
127-
128-
/**
129-
* @inheritDoc
130-
*/
131-
protected _setupTransport(): Transport {
132-
if (!this._options.dsn) {
133-
// We return the noop transport here in case there is no Dsn.
134-
return super._setupTransport();
135-
}
136-
137-
const transportOptions: TransportOptions = {
138-
...this._options.transportOptions,
139-
dsn: this._options.dsn,
140-
tunnel: this._options.tunnel,
141-
sendClientReports: this._options.sendClientReports,
142-
_metadata: this._options._metadata,
143-
};
144-
145-
const api = initAPIDetails(transportOptions.dsn, transportOptions._metadata, transportOptions.tunnel);
146-
const url = getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel);
147-
148-
if (this._options.transport) {
149-
return new this._options.transport(transportOptions);
150-
}
151-
if (supportsFetch()) {
152-
const requestOptions: RequestInit = { ...transportOptions.fetchParameters };
153-
this._newTransport = makeNewFetchTransport({ requestOptions, url });
154-
return new FetchTransport(transportOptions);
155-
}
156-
157-
this._newTransport = makeNewXHRTransport({
158-
url,
159-
headers: transportOptions.headers,
160-
});
161-
return new XHRTransport(transportOptions);
162-
}
163119
}

packages/browser/src/transports/setup.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ export interface BrowserTransportOptions extends BaseTransportOptions {
2222
}
2323

2424
/**
25-
* TODO: additional doc (since this is not part of Client anymore)
26-
* @inheritDoc
25+
* Sets up Browser transports based on the passed `options`. If available, the returned
26+
* transport will use the fetch API. In case fetch is not supported, an XMLHttpRequest
27+
* based transport is created.
28+
*
29+
* @returns an object currently still containing both, the old `Transport` and
30+
* `NewTransport` which will eventually replace `Transport`. Once this is replaced,
31+
* this function will return a ready to use `NewTransport`.
2732
*/
28-
// TODO(v7): refactor to only return newTransport
33+
// TODO(v7): Adjust return value when NewTransport is the default
2934
export function setupBrowserTransport(options: BrowserOptions): { transport: Transport; newTransport?: NewTransport } {
3035
if (!options.dsn) {
3136
// We return the noop transport here in case there is no Dsn.

packages/core/src/baseclient.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { IS_DEBUG_BUILD } from './flags';
3333
import { IntegrationIndex, setupIntegrations } from './integration';
3434
import { createEventEnvelope, createSessionEnvelope } from './request';
3535
import { NewTransport } from './transports/base';
36-
import { NoopTransport } from './transports/noop';
3736

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

@@ -680,13 +679,6 @@ export abstract class BaseClient<O extends Options> implements Client<O> {
680679
);
681680
}
682681

683-
/**
684-
* Sets up the transport so it can be used later to send requests.
685-
*/
686-
protected _setupTransport(): Transport {
687-
return new NoopTransport();
688-
}
689-
690682
/**
691683
* @inheritDoc
692684
*/

packages/core/src/transports/base.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ export interface BaseTransportOptions extends InternalBaseTransportOptions {
5858
url: string;
5959
}
6060

61-
// TODO(v7): Delete
62-
export interface BrowserTransportOptions extends BaseTransportOptions {
63-
// options to pass into fetch request
64-
fetchParams: Record<string, string>;
65-
headers?: Record<string, string>;
66-
sendClientReports?: boolean;
67-
}
68-
6961
export interface NewTransport {
7062
send(request: Envelope): PromiseLike<TransportResponse>;
7163
flush(timeout?: number): PromiseLike<boolean>;

packages/node/src/client.ts

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
import {
2-
BaseClient,
3-
getEnvelopeEndpointWithUrlEncodedAuth,
4-
initAPIDetails,
5-
NewTransport,
6-
Scope,
7-
SDK_VERSION,
8-
} from '@sentry/core';
1+
import { BaseClient, NewTransport, Scope, SDK_VERSION } from '@sentry/core';
92
import { SessionFlusher } from '@sentry/hub';
10-
import { Event, EventHint, Severity, Transport, TransportOptions } from '@sentry/types';
11-
import { logger, makeDsn, resolvedSyncPromise, stackParserFromOptions } from '@sentry/utils';
3+
import { Event, EventHint, Severity, Transport } from '@sentry/types';
4+
import { logger, resolvedSyncPromise, stackParserFromOptions } from '@sentry/utils';
125

136
import { eventFromMessage, eventFromUnknownInput } from './eventbuilder';
147
import { IS_DEBUG_BUILD } from './flags';
15-
import { HTTPSTransport, HTTPTransport, makeNodeTransport } from './transports';
168
import { NodeOptions } from './types';
179

1810
/**
@@ -153,46 +145,4 @@ export class NodeClient extends BaseClient<NodeOptions> {
153145
this._sessionFlusher.incrementSessionStatusCount();
154146
}
155147
}
156-
157-
/**
158-
* @inheritDoc
159-
* TODO(v7): delete
160-
*/
161-
protected _setupTransport(): Transport {
162-
if (!this._options.dsn) {
163-
// We return the noop transport here in case there is no Dsn.
164-
return super._setupTransport();
165-
}
166-
167-
const dsn = makeDsn(this._options.dsn);
168-
169-
const transportOptions: TransportOptions = {
170-
...this._options.transportOptions,
171-
...(this._options.httpProxy && { httpProxy: this._options.httpProxy }),
172-
...(this._options.httpsProxy && { httpsProxy: this._options.httpsProxy }),
173-
...(this._options.caCerts && { caCerts: this._options.caCerts }),
174-
dsn: this._options.dsn,
175-
tunnel: this._options.tunnel,
176-
_metadata: this._options._metadata,
177-
};
178-
179-
if (this._options.transport) {
180-
return new this._options.transport(transportOptions);
181-
}
182-
183-
const api = initAPIDetails(transportOptions.dsn, transportOptions._metadata, transportOptions.tunnel);
184-
const url = getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel);
185-
186-
this._newTransport = makeNodeTransport({
187-
url,
188-
headers: transportOptions.headers,
189-
proxy: transportOptions.httpProxy,
190-
caCerts: transportOptions.caCerts,
191-
});
192-
193-
if (dsn.protocol === 'http') {
194-
return new HTTPTransport(transportOptions);
195-
}
196-
return new HTTPSTransport(transportOptions);
197-
}
198148
}

packages/node/src/sdk.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ export function init(options: NodeOptions = {}): void {
131131
setHubOnCarrier(carrier, getCurrentHub());
132132
}
133133

134-
// TODO(v7): Init transport here and pass it to initAndBind
135134
const { transport, newTransport } = setupNodeTransport(options);
136135
initAndBind(NodeClient, options, transport, newTransport);
137136

packages/node/src/transports/setup.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import { NodeOptions } from '../types';
66
import { HTTPSTransport, HTTPTransport, makeNodeTransport } from '.';
77

88
/**
9-
* TODO(v7): Add documentation
10-
* @inheritDoc
9+
* Sets up Node transport based on the passed `options`.
10+
*
11+
* @returns an object currently still containing both, the old `Transport` and
12+
* `NewTransport` which will eventually replace `Transport`. Once this is replaced,
13+
* this function will return a ready to use `NewTransport`.
1114
*/
12-
// TODO(v7): Adjust when NewTransport is the default
15+
// TODO(v7): Adjust return value when NewTransport is the default
1316
export function setupNodeTransport(options: NodeOptions): { transport: Transport; newTransport?: NewTransport } {
1417
if (!options.dsn) {
1518
// We return the noop transport here in case there is no Dsn.

0 commit comments

Comments
 (0)