Skip to content

Commit f282c6c

Browse files
committed
the rest of the owl
1 parent 0914768 commit f282c6c

File tree

17 files changed

+59
-205
lines changed

17 files changed

+59
-205
lines changed

MIGRATION.md

-6
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ For our efforts to reduce bundle size of the SDK we had to remove and refactor p
115115
[#4919](https://github.com/getsentry/sentry-javascript/pull/4919)). `Backend` was an unnecessary abstraction which is
116116
not present in other Sentry SDKs. For the sake of reducing complexity, increasing consistency with other Sentry SDKs and
117117
decreasing bundle-size, `Backend` was removed.
118-
<!-- TODO(v7): Add more info and PR link for passing transports in options once this is done -->
119-
<!-- TODO(v7): This needs refinement once NewTransport is the default (maybe this should get its own section with an expamp) -->
120-
- Inject transport into client instead of initializing it in the client in `setupTransport` (see
121-
[#4921](https://github.com/getsentry/sentry-javascript/pull/4921/)). If you are creating your own `Client` or
122-
calling `initAndBind`, you will have to supply your desired transport. Either provide a custom one or call
123-
`setupBrowserTransport` or `setupNodeTransport` for default transports, depending on your requirements.
124118
- Remove support for Opera browser pre v15
125119

126120
# Upgrading from 6.17.x to 6.18.0

packages/browser/src/client.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { BaseClient, NewTransport, Scope, SDK_VERSION } from '@sentry/core';
2-
import { ClientOptions, Event, EventHint, Options, Severity, SeverityLevel, Transport } from '@sentry/types';
1+
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
2+
import { ClientOptions, Event, EventHint, Options, Severity, SeverityLevel } from '@sentry/types';
33
import { getGlobalObject, logger, stackParserFromOptions } from '@sentry/utils';
44

55
import { eventFromException, eventFromMessage } from './eventbuilder';
@@ -47,7 +47,7 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
4747
*
4848
* @param options Configuration options for this SDK.
4949
*/
50-
public constructor(options: BrowserClientOptions, transport: Transport, newTransport?: NewTransport) {
50+
public constructor(options: BrowserClientOptions) {
5151
options._metadata = options._metadata || {};
5252
options._metadata.sdk = options._metadata.sdk || {
5353
name: 'sentry.javascript.browser',
@@ -59,7 +59,7 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
5959
],
6060
version: SDK_VERSION,
6161
};
62-
super(options, transport, newTransport);
62+
super(options);
6363
}
6464

6565
/**

packages/browser/src/sdk.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import { IS_DEBUG_BUILD } from './flags';
1414
import { ReportDialogOptions, wrap as internalWrap } from './helpers';
1515
import { Breadcrumbs, Dedupe, GlobalHandlers, LinkedErrors, TryCatch, UserAgent } from './integrations';
1616
import { defaultStackParsers } from './stack-parsers';
17-
import { FetchTransport, XHRTransport } from './transports';
18-
import { setupBrowserTransport } from './transports/setup';
17+
import { makeNewFetchTransport, makeNewXHRTransport } from './transports';
1918

2019
export const defaultIntegrations = [
2120
new CoreIntegrations.InboundFilters(),
@@ -105,17 +104,15 @@ export function init(options: BrowserOptions = {}): void {
105104
if (options.stackParser === undefined) {
106105
options.stackParser = defaultStackParsers;
107106
}
108-
const { transport, newTransport } = setupBrowserTransport(options);
109107

110108
const clientOptions: BrowserClientOptions = {
111109
...options,
112110
stackParser: stackParserFromOptions(options),
113111
integrations: getIntegrationsToSetup(options),
114-
// TODO(v7): get rid of transport being passed down below
115-
transport: options.transport || (supportsFetch() ? FetchTransport : XHRTransport),
112+
transport: options.transport || (supportsFetch() ? makeNewFetchTransport : makeNewXHRTransport),
116113
};
117114

118-
initAndBind(BrowserClient, clientOptions, transport, newTransport);
115+
initAndBind(BrowserClient, clientOptions);
119116

120117
if (options.autoSessionTracking) {
121118
startSessionTracking();

packages/browser/src/transports/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ export { XHRTransport } from './xhr';
44

55
export { makeNewFetchTransport } from './new-fetch';
66
export { makeNewXHRTransport } from './new-xhr';
7-
8-
export { setupBrowserTransport } from './setup';

packages/browser/src/transports/new-fetch.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import {
2-
BaseTransportOptions,
3-
createTransport,
4-
NewTransport,
5-
TransportMakeRequestResponse,
6-
TransportRequest,
7-
} from '@sentry/core';
1+
import { createTransport } from '@sentry/core';
2+
import { BaseTransportOptions, NewTransport, TransportMakeRequestResponse, TransportRequest } from '@sentry/types';
3+
import { resolvedSyncPromise } from '@sentry/utils';
84

95
import { FetchImpl, getNativeFetchImplementation } from './utils';
106

@@ -20,6 +16,10 @@ export function makeNewFetchTransport(
2016
nativeFetch: FetchImpl = getNativeFetchImplementation(),
2117
): NewTransport {
2218
function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {
19+
if (!options.url) {
20+
return resolvedSyncPromise({ statusCode: 400 });
21+
}
22+
2323
const requestOptions: RequestInit = {
2424
body: request.body,
2525
method: 'POST',

packages/browser/src/transports/new-xhr.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import {
2-
BaseTransportOptions,
3-
createTransport,
4-
NewTransport,
5-
TransportMakeRequestResponse,
6-
TransportRequest,
7-
} from '@sentry/core';
8-
import { SyncPromise } from '@sentry/utils';
1+
import { createTransport } from '@sentry/core';
2+
import { BaseTransportOptions, NewTransport, TransportMakeRequestResponse, TransportRequest } from '@sentry/types';
3+
import { resolvedSyncPromise, SyncPromise } from '@sentry/utils';
94

105
/**
116
* The DONE ready state for XmlHttpRequest
@@ -26,6 +21,10 @@ export interface XHRTransportOptions extends BaseTransportOptions {
2621
*/
2722
export function makeNewXHRTransport(options: XHRTransportOptions): NewTransport {
2823
function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {
24+
if (!options.url) {
25+
return resolvedSyncPromise({ statusCode: 400 });
26+
}
27+
2928
return new SyncPromise<TransportMakeRequestResponse>((resolve, _reject) => {
3029
const xhr = new XMLHttpRequest();
3130

packages/browser/src/transports/setup.ts

-71
This file was deleted.

packages/core/src/baseclient.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Severity,
1212
SeverityLevel,
1313
Transport,
14+
NewTransport,
1415
} from '@sentry/types';
1516
import {
1617
checkOrSetAlreadyCaught,
@@ -29,7 +30,7 @@ import {
2930
uuid4,
3031
} from '@sentry/utils';
3132

32-
import { APIDetails, initAPIDetails } from './api';
33+
import { APIDetails, initAPIDetails, getEnvelopeEndpointWithUrlEncodedAuth } from './api';
3334
import { IS_DEBUG_BUILD } from './flags';
3435
import { IntegrationIndex, setupIntegrations } from './integration';
3536
import { createEventEnvelope, createSessionEnvelope } from './request';
@@ -82,7 +83,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
8283
protected _numProcessing: number = 0;
8384

8485
/** Cached transport used internally. */
85-
protected _transport: Transport;
86+
protected _transport: NewTransport;
8687

8788
/** New v7 Transport that is initialized alongside the old one */
8889
protected _newTransport?: NewTransport;
@@ -94,25 +95,20 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
9495
* @param transport The (old) Transport instance for the client to use (TODO(v7): remove)
9596
* @param newTransport The NewTransport instance for the client to use
9697
*/
97-
protected constructor(options: O, transport: Transport, newTransport?: NewTransport) {
98+
protected constructor(options: O) {
9899
this._options = options;
99100

101+
let url;
100102
if (options.dsn) {
101103
this._dsn = makeDsn(options.dsn);
104+
// TODO(v7): Figure out what to do with transport when dsn is not defined
105+
const api = initAPIDetails(this._dsn, options._metadata, options.tunnel);
106+
url = getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel);
102107
} else {
103108
IS_DEBUG_BUILD && logger.warn('No DSN provided, client will not do anything.');
104109
}
105110

106-
// TODO(v7): remove old transport
107-
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-
};
111+
this._transport = options.transport({ ...options.transportOptions, url: url || '' });
116112
}
117113

118114
/**

packages/core/src/index.ts

-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
export type { APIDetails } from './api';
22
export type { ClientClass } from './sdk';
3-
export type {
4-
BaseTransportOptions,
5-
NewTransport,
6-
TransportMakeRequestResponse,
7-
TransportRequest,
8-
TransportRequestExecutor,
9-
} from './transports/base';
103

114
export {
125
addBreadcrumb,

packages/core/src/sdk.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { getCurrentHub } from '@sentry/hub';
2-
import { Client, ClientOptions, Transport } from '@sentry/types';
2+
import { Client, ClientOptions, NewTransport, Transport } from '@sentry/types';
33
import { logger } from '@sentry/utils';
44

55
import { IS_DEBUG_BUILD } from './flags';
6-
import { NewTransport } from './transports/base';
76

87
/** A class object that can instantiate Client objects. */
9-
export type ClientClass<F extends Client, O extends ClientOptions> = new (
10-
options: O,
11-
transport: Transport,
12-
newTransport?: NewTransport,
13-
) => F;
8+
export type ClientClass<F extends Client, O extends ClientOptions> = new (options: O) => F;
149

1510
/**
1611
* Internal function to create a new SDK client instance. The client is
@@ -22,8 +17,6 @@ export type ClientClass<F extends Client, O extends ClientOptions> = new (
2217
export function initAndBind<F extends Client, O extends ClientOptions>(
2318
clientClass: ClientClass<F, O>,
2419
options: O,
25-
transport: Transport,
26-
newTransport?: NewTransport,
2720
): void {
2821
if (options.debug === true) {
2922
if (IS_DEBUG_BUILD) {
@@ -40,6 +33,6 @@ export function initAndBind<F extends Client, O extends ClientOptions>(
4033
scope.update(options.initialScope);
4134
}
4235

43-
const client = new clientClass(options, transport, newTransport);
36+
const client = new clientClass(options);
4437
hub.bindClient(client);
4538
}

packages/node/src/client.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { BaseClient, NewTransport, Scope, SDK_VERSION } from '@sentry/core';
1+
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
22
import { SessionFlusher } from '@sentry/hub';
3-
import { Event, EventHint, Severity, SeverityLevel, Transport } from '@sentry/types';
3+
import { Event, EventHint, Severity, SeverityLevel } from '@sentry/types';
44
import { logger, resolvedSyncPromise, stackParserFromOptions } from '@sentry/utils';
55

66
import { eventFromMessage, eventFromUnknownInput } from './eventbuilder';
@@ -20,7 +20,7 @@ export class NodeClient extends BaseClient<NodeClientOptions> {
2020
* Creates a new Node SDK instance.
2121
* @param options Configuration options for this SDK.
2222
*/
23-
public constructor(options: NodeClientOptions, transport: Transport, newTransport?: NewTransport) {
23+
public constructor(options: NodeClientOptions) {
2424
options._metadata = options._metadata || {};
2525
options._metadata.sdk = options._metadata.sdk || {
2626
name: 'sentry.javascript.node',
@@ -33,7 +33,7 @@ export class NodeClient extends BaseClient<NodeClientOptions> {
3333
version: SDK_VERSION,
3434
};
3535

36-
super(options, transport, newTransport);
36+
super(options);
3737
}
3838

3939
/**

packages/node/src/sdk.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { NodeClient } from './client';
88
import { IS_DEBUG_BUILD } from './flags';
99
import { Console, ContextLines, Http, LinkedErrors, OnUncaughtException, OnUnhandledRejection } from './integrations';
1010
import { nodeStackParser } from './stack-parser';
11-
import { HTTPSTransport, HTTPTransport, setupNodeTransport } from './transports';
11+
import { makeNodeTransport } from './transports';
1212
import { NodeClientOptions, NodeOptions } from './types';
1313

1414
export const defaultIntegrations = [
@@ -131,18 +131,15 @@ export function init(options: NodeOptions = {}): void {
131131
setHubOnCarrier(carrier, getCurrentHub());
132132
}
133133

134-
const { transport, newTransport } = setupNodeTransport(options);
135-
136134
// TODO(v7): Refactor this to reduce the logic above
137135
const clientOptions: NodeClientOptions = {
138136
...options,
139137
stackParser: stackParserFromOptions(options),
140138
integrations: getIntegrationsToSetup(options),
141-
// TODO(v7): Fix me when we switch to new transports entirely.
142-
transport: options.transport || (transport instanceof HTTPTransport ? HTTPTransport : HTTPSTransport),
139+
transport: options.transport || makeNodeTransport,
143140
};
144141

145-
initAndBind(NodeClient, clientOptions, transport, newTransport);
142+
initAndBind(NodeClient, clientOptions);
146143

147144
if (options.autoSessionTracking) {
148145
startSessionTracking();

packages/node/src/transports/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ export { BaseTransport } from './base';
44
export { HTTPTransport } from './http';
55
export { HTTPSTransport } from './https';
66
export { makeNodeTransport } from './new';
7-
export { setupNodeTransport } from './setup';

0 commit comments

Comments
 (0)