-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
client.ts
131 lines (115 loc) · 4.93 KB
/
client.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { EventDropReason } from './clientreport';
import { DataCategory } from './datacategory';
import { DsnComponents } from './dsn';
import { Event, EventHint } from './event';
import { Integration, IntegrationClass } from './integration';
import { ClientOptions } from './options';
import { Scope } from './scope';
import { Session, SessionAggregates } from './session';
import { Severity, SeverityLevel } from './severity';
import { Transport } from './transport';
/**
* User-Facing Sentry SDK Client.
*
* This interface contains all methods to interface with the SDK once it has
* been installed. It allows to send events to Sentry, record breadcrumbs and
* set a context included in every event. Since the SDK mutates its environment,
* there will only be one instance during runtime.
*
*/
export interface Client<O extends ClientOptions = ClientOptions> {
/**
* Captures an exception event and sends it to Sentry.
*
* @param exception An exception-like object.
* @param hint May contain additional information about the original exception.
* @param scope An optional scope containing event metadata.
* @returns The event id
*/
captureException(exception: any, hint?: EventHint, scope?: Scope): string | undefined;
/**
* Captures a message event and sends it to Sentry.
*
* @param message The message to send to Sentry.
* @param level Define the level of the message.
* @param hint May contain additional information about the original exception.
* @param scope An optional scope containing event metadata.
* @returns The event id
*/
captureMessage(
message: string,
// eslint-disable-next-line deprecation/deprecation
level?: Severity | SeverityLevel,
hint?: EventHint,
scope?: Scope,
): string | undefined;
/**
* Captures a manually created event and sends it to Sentry.
*
* @param event The event to send to Sentry.
* @param hint May contain additional information about the original exception.
* @param scope An optional scope containing event metadata.
* @returns The event id
*/
captureEvent(event: Event, hint?: EventHint, scope?: Scope): string | undefined;
/**
* Captures a session
*
* @param session Session to be delivered
*/
captureSession?(session: Session): void;
/** Returns the current Dsn. */
getDsn(): DsnComponents | undefined;
/** Returns the current options. */
getOptions(): O;
/**
* Returns the transport that is used by the client.
* Please note that the transport gets lazy initialized so it will only be there once the first event has been sent.
*
* @returns The transport.
*/
getTransport(): Transport | undefined;
/**
* Flush the event queue and set the client to `enabled = false`. See {@link Client.flush}.
*
* @param timeout Maximum time in ms the client should wait before shutting down. Omitting this parameter will cause
* the client to wait until all events are sent before disabling itself.
* @returns A promise which resolves to `true` if the flush completes successfully before the timeout, or `false` if
* it doesn't.
*/
close(timeout?: number): PromiseLike<boolean>;
/**
* Wait for all events to be sent or the timeout to expire, whichever comes first.
*
* @param timeout Maximum time in ms the client should wait for events to be flushed. Omitting this parameter will
* cause the client to wait until all events are sent before resolving the promise.
* @returns A promise that will resolve with `true` if all events are sent before the timeout, or `false` if there are
* still events in the queue when the timeout is reached.
*/
flush(timeout?: number): PromiseLike<boolean>;
/** Returns the client's instance of the given integration class, it any. */
getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;
/** This is an internal function to setup all integrations that should run on the client */
setupIntegrations(): void;
/** Creates an {@link Event} from all inputs to `captureException` and non-primitive inputs to `captureMessage`. */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
eventFromException(exception: any, hint?: EventHint): PromiseLike<Event>;
/** Creates an {@link Event} from primitive inputs to `captureMessage`. */
eventFromMessage(
message: string,
// eslint-disable-next-line deprecation/deprecation
level?: Severity | SeverityLevel,
hint?: EventHint,
): PromiseLike<Event>;
/** Submits the event to Sentry */
sendEvent(event: Event, hint?: EventHint): void;
/** Submits the session to Sentry */
sendSession(session: Session | SessionAggregates): void;
/**
* Record on the client that an event got dropped (ie, an event that will not be sent to sentry).
*
* @param reason The reason why the event got dropped.
* @param category The data category of the dropped event.
*/
recordDroppedEvent(reason: EventDropReason, category: DataCategory): void;
}