-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathbackend.ts
77 lines (68 loc) · 2.28 KB
/
backend.ts
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { BaseBackend } from '@sentry/core';
import { Event, EventHint, Options, Severity, Transport } from '@sentry/types';
import { supportsFetch } from '@sentry/utils';
import { eventFromException, eventFromMessage } from './eventbuilder';
import { FetchTransport, XHRTransport } from './transports';
/**
* Configuration options for the Sentry Browser SDK.
* @see BrowserClient for more information.
*/
export interface BrowserOptions extends Options {
/**
* A pattern for error URLs which should exclusively be sent to Sentry.
* This is the opposite of {@link Options.denyUrls}.
* By default, all errors will be sent.
*/
allowUrls?: Array<string | RegExp>;
/**
* A pattern for error URLs which should not be sent to Sentry.
* To allow certain errors instead, use {@link Options.allowUrls}.
* By default, all errors will be sent.
*/
denyUrls?: Array<string | RegExp>;
/** @deprecated use {@link Options.allowUrls} instead. */
whitelistUrls?: Array<string | RegExp>;
/** @deprecated use {@link Options.denyUrls} instead. */
blacklistUrls?: Array<string | RegExp>;
}
/**
* The Sentry Browser SDK Backend.
* @hidden
*/
export class BrowserBackend extends BaseBackend<BrowserOptions> {
/**
* @inheritDoc
*/
public eventFromException(exception: unknown, hint?: EventHint): PromiseLike<Event> {
return eventFromException(this._options, exception, hint);
}
/**
* @inheritDoc
*/
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike<Event> {
return eventFromMessage(this._options, message, level, hint);
}
/**
* @inheritDoc
*/
protected _setupTransport(): Transport {
if (!this._options.dsn) {
// We return the noop transport here in case there is no Dsn.
return super._setupTransport();
}
const transportOptions = {
...this._options.transportOptions,
dsn: this._options.dsn,
tunnel: this._options.tunnel,
sendClientReports: this._options.sendClientReports,
_metadata: this._options._metadata,
};
if (this._options.transport) {
return new this._options.transport(transportOptions);
}
if (supportsFetch()) {
return new FetchTransport(transportOptions);
}
return new XHRTransport(transportOptions);
}
}