-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathindex.ts
More file actions
33 lines (30 loc) · 1.06 KB
/
index.ts
File metadata and controls
33 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/core';
import { createTransport, suppressTracing } from '@sentry/core';
/**
* Creates a Transport that uses the Fetch API to send events to Sentry.
*/
export function makeFetchTransport(options: BaseTransportOptions): Transport {
function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {
const requestOptions: RequestInit = {
body: request.body as BodyInit,
method: 'POST',
headers: options.headers,
};
try {
return suppressTracing(() => {
return fetch(options.url, requestOptions).then(response => {
return {
statusCode: response.status,
headers: {
'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
'retry-after': response.headers.get('Retry-After'),
},
};
});
});
} catch (e) {
return Promise.reject(e);
}
}
return createTransport(options, makeRequest);
}