-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathindex.ts
More file actions
51 lines (46 loc) · 1.61 KB
/
index.ts
File metadata and controls
51 lines (46 loc) · 1.61 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/core';
import { consoleSandbox, createTransport, debug, suppressTracing } from '@sentry/core';
/**
* Creates a Transport that uses the Fetch API to send events to Sentry.
*/
export function makeFetchTransport(options: BaseTransportOptions): Transport {
const url = new URL(options.url);
Deno.permissions
.query({ name: 'net', host: url.host })
.then(({ state }) => {
if (state !== 'granted') {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(`Sentry SDK requires 'net' permission to send events.
Run with '--allow-net=${url.host}' to grant the required permissions.`);
});
}
})
.catch(() => {
debug.warn('Failed to read the "net" permission.');
});
function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {
const requestOptions: RequestInit = {
body: request.body,
method: 'POST',
referrerPolicy: 'strict-origin',
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);
}