-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
client.ts
191 lines (166 loc) · 6.99 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import type { EventDropReason } from './clientreport';
import type { DataCategory } from './datacategory';
import type { DsnComponents } from './dsn';
import type { Envelope } from './envelope';
import type { Event, EventHint } from './event';
import type { Integration, IntegrationClass } from './integration';
import type { ClientOptions } from './options';
import type { Scope } from './scope';
import type { SdkMetadata } from './sdkmetadata';
import type { Session, SessionAggregates } from './session';
import type { Severity, SeverityLevel } from './severity';
import type { Transaction } from './transaction';
import type { Transport, TransportMakeRequestResponse } 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;
/**
* @inheritdoc
*
* TODO (v8): Make this a required method.
*/
getSdkMetadata?(): SdkMetadata | undefined;
/**
* 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;
/**
* Add an integration to the client.
* This can be used to e.g. lazy load integrations.
* In most cases, this should not be necessary, and you're better off just passing the integrations via `integrations: []` at initialization time.
* However, if you find the need to conditionally load & add an integration, you can use `addIntegration` to do so.
*
* TODO (v8): Make this a required method.
* */
addIntegration?(integration: Integration): void;
/** 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.
* @param event The dropped event.
*/
recordDroppedEvent(reason: EventDropReason, dataCategory: DataCategory, event?: Event): void;
// HOOKS
// TODO(v8): Make the hooks non-optional.
/**
* Register a callback for transaction start and finish.
*/
on?(hook: 'startTransaction' | 'finishTransaction', callback: (transaction: Transaction) => void): void;
/**
* Register a callback for transaction start and finish.
*/
on?(hook: 'beforeEnvelope', callback: (envelope: Envelope) => void): void;
/**
* Register a callback for when an event has been sent.
*/
on?(
hook: 'afterSendEvent',
callback: (event: Event, sendResponse: TransportMakeRequestResponse | void) => void,
): void;
/**
* Fire a hook event for transaction start and finish. Expects to be given a transaction as the
* second argument.
*/
emit?(hook: 'startTransaction' | 'finishTransaction', transaction: Transaction): void;
/*
* Fire a hook event for envelope creation and sending. Expects to be given an envelope as the
* second argument.
*/
emit?(hook: 'beforeEnvelope', envelope: Envelope): void;
/*
* Fire a hook event after sending an event. Expects to be given an Event as the
* second argument.
*/
emit?(hook: 'afterSendEvent', event: Event, sendResponse: TransportMakeRequestResponse | void): void;
}