Skip to content

Commit 29d3739

Browse files
committed
feat: Delete old transports
Delete old transports as we've switched entirely to new v7 transports.
1 parent d9eaaff commit 29d3739

File tree

35 files changed

+1000
-3994
lines changed

35 files changed

+1000
-3994
lines changed

packages/browser/src/transports/base.ts

-212
This file was deleted.
+30-77
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,39 @@
1-
import { Event, Response, SentryRequest, Session, TransportOptions } from '@sentry/types';
2-
import { SentryError, supportsReferrerPolicy, SyncPromise } from '@sentry/utils';
1+
import { createTransport } from '@sentry/core';
2+
import { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/types';
33

4-
import { BaseTransport } from './base';
54
import { FetchImpl, getNativeFetchImplementation } from './utils';
65

7-
/** `fetch` based transport */
8-
export class FetchTransport extends BaseTransport {
9-
/**
10-
* Fetch API reference which always points to native browser implementation.
11-
*/
12-
private _fetch: typeof fetch;
13-
14-
public constructor(options: TransportOptions, fetchImpl: FetchImpl = getNativeFetchImplementation()) {
15-
super(options);
16-
this._fetch = fetchImpl;
17-
}
18-
19-
/**
20-
* @param sentryRequest Prepared SentryRequest to be delivered
21-
* @param originalPayload Original payload used to create SentryRequest
22-
*/
23-
protected _sendRequest(sentryRequest: SentryRequest, originalPayload: Event | Session): PromiseLike<Response> {
24-
// eslint-disable-next-line deprecation/deprecation
25-
if (this._isRateLimited(sentryRequest.type)) {
26-
this.recordLostEvent('ratelimit_backoff', sentryRequest.type);
27-
28-
return Promise.reject({
29-
event: originalPayload,
30-
type: sentryRequest.type,
31-
// eslint-disable-next-line deprecation/deprecation
32-
reason: `Transport for ${sentryRequest.type} requests locked till ${this._disabledUntil(
33-
sentryRequest.type,
34-
)} due to too many requests.`,
35-
status: 429,
36-
});
37-
}
6+
export interface FetchTransportOptions extends BaseTransportOptions {
7+
requestOptions?: RequestInit;
8+
}
389

39-
const options: RequestInit = {
40-
body: sentryRequest.body,
10+
/**
11+
* Creates a Transport that uses the Fetch API to send events to Sentry.
12+
*/
13+
export function makeNewFetchTransport(
14+
options: FetchTransportOptions,
15+
nativeFetch: FetchImpl = getNativeFetchImplementation(),
16+
): Transport {
17+
function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {
18+
const requestOptions: RequestInit = {
19+
body: request.body,
4120
method: 'POST',
42-
// Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default'
43-
// (see https://caniuse.com/#feat=referrer-policy),
44-
// it doesn't. And it throws an exception instead of ignoring this parameter...
45-
// REF: https://github.com/getsentry/raven-js/issues/1233
46-
referrerPolicy: (supportsReferrerPolicy() ? 'origin' : '') as ReferrerPolicy,
21+
referrerPolicy: 'origin',
22+
...options.requestOptions,
4723
};
48-
if (this.options.fetchParameters !== undefined) {
49-
Object.assign(options, this.options.fetchParameters);
50-
}
51-
if (this.options.headers !== undefined) {
52-
options.headers = this.options.headers;
53-
}
5424

55-
return this._buffer
56-
.add(
57-
() =>
58-
new SyncPromise<Response>((resolve, reject) => {
59-
void this._fetch(sentryRequest.url, options)
60-
.then(response => {
61-
const headers = {
62-
'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
63-
'retry-after': response.headers.get('Retry-After'),
64-
};
65-
this._handleResponse({
66-
requestType: sentryRequest.type,
67-
response,
68-
headers,
69-
resolve,
70-
reject,
71-
});
72-
})
73-
.catch(reject);
74-
}),
75-
)
76-
.then(undefined, reason => {
77-
// It's either buffer rejection or any other xhr/fetch error, which are treated as NetworkError.
78-
if (reason instanceof SentryError) {
79-
this.recordLostEvent('queue_overflow', sentryRequest.type);
80-
} else {
81-
this.recordLostEvent('network_error', sentryRequest.type);
82-
}
83-
throw reason;
84-
});
25+
return nativeFetch(options.url, requestOptions).then(response => {
26+
return response.text().then(body => ({
27+
body,
28+
headers: {
29+
'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
30+
'retry-after': response.headers.get('Retry-After'),
31+
},
32+
reason: response.statusText,
33+
statusCode: response.status,
34+
}));
35+
});
8536
}
37+
38+
return createTransport({ bufferSize: options.bufferSize }, makeRequest);
8639
}
+2-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
export { BaseTransport } from './base';
2-
export { FetchTransport } from './fetch';
3-
export { XHRTransport } from './xhr';
4-
5-
export { makeNewFetchTransport } from './new-fetch';
6-
export { makeNewXHRTransport } from './new-xhr';
1+
export { makeNewFetchTransport } from './fetch';
2+
export { makeNewXHRTransport } from './xhr';

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

-39
This file was deleted.

0 commit comments

Comments
 (0)