Skip to content

Commit 86cfd73

Browse files
committed
delete setupTransport(), cleanup TODOs, add doc
1 parent a555fad commit 86cfd73

File tree

7 files changed

+20
-123
lines changed

7 files changed

+20
-123
lines changed

packages/browser/src/client.ts

+3-47
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, SeverityLevel, 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, SeverityLevel, 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.
@@ -129,40 +121,4 @@ export class BrowserClient extends BaseClient<BrowserOptions> {
129121
}
130122
super._sendEvent(event);
131123
}
132-
133-
/**
134-
* @inheritDoc
135-
*/
136-
protected _setupTransport(): Transport {
137-
if (!this._options.dsn) {
138-
// We return the noop transport here in case there is no Dsn.
139-
return super._setupTransport();
140-
}
141-
142-
const transportOptions: TransportOptions = {
143-
...this._options.transportOptions,
144-
dsn: this._options.dsn,
145-
tunnel: this._options.tunnel,
146-
sendClientReports: this._options.sendClientReports,
147-
_metadata: this._options._metadata,
148-
};
149-
150-
const api = initAPIDetails(transportOptions.dsn, transportOptions._metadata, transportOptions.tunnel);
151-
const url = getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel);
152-
153-
if (this._options.transport) {
154-
return new this._options.transport(transportOptions);
155-
}
156-
if (supportsFetch()) {
157-
const requestOptions: RequestInit = { ...transportOptions.fetchParameters };
158-
this._newTransport = makeNewFetchTransport({ requestOptions, url });
159-
return new FetchTransport(transportOptions);
160-
}
161-
162-
this._newTransport = makeNewXHRTransport({
163-
url,
164-
headers: transportOptions.headers,
165-
});
166-
return new XHRTransport(transportOptions);
167-
}
168124
}

packages/browser/src/transports/setup.ts

+8-3
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

-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { IS_DEBUG_BUILD } from './flags';
3434
import { IntegrationIndex, setupIntegrations } from './integration';
3535
import { createEventEnvelope, createSessionEnvelope } from './request';
3636
import { NewTransport } from './transports/base';
37-
import { NoopTransport } from './transports/noop';
3837

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

@@ -687,13 +686,6 @@ export abstract class BaseClient<O extends Options> implements Client<O> {
687686
);
688687
}
689688

690-
/**
691-
* Sets up the transport so it can be used later to send requests.
692-
*/
693-
protected _setupTransport(): Transport {
694-
return new NoopTransport();
695-
}
696-
697689
/**
698690
* @inheritDoc
699691
*/

packages/core/src/transports/base.ts

-8
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

+3-53
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, SeverityLevel, Transport, TransportOptions } from '@sentry/types';
11-
import { logger, makeDsn, resolvedSyncPromise, stackParserFromOptions } from '@sentry/utils';
3+
import { Event, EventHint, Severity, SeverityLevel, 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
/**
@@ -158,46 +150,4 @@ export class NodeClient extends BaseClient<NodeOptions> {
158150
this._sessionFlusher.incrementSessionStatusCount();
159151
}
160152
}
161-
162-
/**
163-
* @inheritDoc
164-
* TODO(v7): delete
165-
*/
166-
protected _setupTransport(): Transport {
167-
if (!this._options.dsn) {
168-
// We return the noop transport here in case there is no Dsn.
169-
return super._setupTransport();
170-
}
171-
172-
const dsn = makeDsn(this._options.dsn);
173-
174-
const transportOptions: TransportOptions = {
175-
...this._options.transportOptions,
176-
...(this._options.httpProxy && { httpProxy: this._options.httpProxy }),
177-
...(this._options.httpsProxy && { httpsProxy: this._options.httpsProxy }),
178-
...(this._options.caCerts && { caCerts: this._options.caCerts }),
179-
dsn: this._options.dsn,
180-
tunnel: this._options.tunnel,
181-
_metadata: this._options._metadata,
182-
};
183-
184-
if (this._options.transport) {
185-
return new this._options.transport(transportOptions);
186-
}
187-
188-
const api = initAPIDetails(transportOptions.dsn, transportOptions._metadata, transportOptions.tunnel);
189-
const url = getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel);
190-
191-
this._newTransport = makeNodeTransport({
192-
url,
193-
headers: transportOptions.headers,
194-
proxy: transportOptions.httpProxy,
195-
caCerts: transportOptions.caCerts,
196-
});
197-
198-
if (dsn.protocol === 'http') {
199-
return new HTTPTransport(transportOptions);
200-
}
201-
return new HTTPSTransport(transportOptions);
202-
}
203153
}

packages/node/src/sdk.ts

-1
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

+6-3
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)