Repository navigation
Expand file tree
/
Copy pathclient.ts
More file actions
313 lines (270 loc) · 11.7 KB
/
Copy pathclient.ts
File metadata and controls
313 lines (270 loc) · 11.7 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import type { Breadcrumb, BreadcrumbHint } from './breadcrumb';
import type { CheckIn, MonitorConfig } from './checkin';
import type { EventDropReason } from './clientreport';
import type { DataCategory } from './datacategory';
import type { DsnComponents } from './dsn';
import type { DynamicSamplingContext, Envelope } from './envelope';
import type { Event, EventHint } from './event';
import type { EventProcessor } from './eventprocessor';
import type { FeedbackEvent } from './feedback';
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;
/**
* Create a cron monitor check in and send it to Sentry. This method is not available on all clients.
*
* @param checkIn An object that describes a check in.
* @param upsertMonitorConfig An optional object that describes a monitor config. Use this if you want
* to create a monitor automatically when sending a check in.
* @param scope An optional scope containing event metadata.
* @returns A string representing the id of the check in.
*/
captureCheckIn?(checkIn: CheckIn, monitorConfig?: MonitorConfig, scope?: Scope): string;
/** 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>;
/**
* Adds an event processor that applies to any event processed by this client.
*
* TODO (v8): Make this a required method.
*/
addEventProcessor?(eventProcessor: EventProcessor): void;
/**
* Get all added event processors for this client.
*
* TODO (v8): Make this a required method.
*/
getEventProcessors?(): EventProcessor[];
/** 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(forceInitialize?: boolean): 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.
/* eslint-disable @typescript-eslint/unified-signatures */
/**
* Register a callback for transaction start.
* Receives the transaction as argument.
*/
on?(hook: 'startTransaction', callback: (transaction: Transaction) => void): void;
/**
* Register a callback for transaction finish.
* Receives the transaction as argument.
*/
on?(hook: '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 before sending an event.
* This is called right before an event is sent and should not be used to mutate the event.
* Receives an Event & EventHint as arguments.
*/
on?(hook: 'beforeSendEvent', callback: (event: Event, hint?: EventHint | undefined) => void): void;
/**
* Register a callback for preprocessing an event,
* before it is passed to (global) event processors.
* Receives an Event & EventHint as arguments.
*/
on?(hook: 'preprocessEvent', callback: (event: Event, hint?: EventHint | undefined) => void): void;
/**
* Register a callback for when an event has been sent.
*/
on?(
hook: 'afterSendEvent',
callback: (event: Event, sendResponse: TransportMakeRequestResponse | void) => void,
): void;
/**
* Register a callback before a breadcrumb is added.
*/
on?(hook: 'beforeAddBreadcrumb', callback: (breadcrumb: Breadcrumb, hint?: BreadcrumbHint) => void): void;
/**
* Register a callback when a DSC (Dynamic Sampling Context) is created.
*/
on?(hook: 'createDsc', callback: (dsc: DynamicSamplingContext) => void): void;
/**
* Register a callback when an OpenTelemetry span is ended (in @sentry/opentelemetry-node).
* The option argument may be mutated to drop the span.
*/
on?(hook: 'otelSpanEnd', callback: (otelSpan: unknown, mutableOptions: { drop: boolean }) => void): void;
/**
* Register a callback when a Feedback event has been prepared.
* This should be used to mutate the event. The options argument can hint
* about what kind of mutation it expects.
*/
on?(
hook: 'beforeSendFeedback',
callback: (feedback: FeedbackEvent, options?: { includeReplay?: boolean }) => void,
): void;
/**
* Fire a hook event for transaction start.
* Expects to be given a transaction as the second argument.
*/
emit?(hook: 'startTransaction', transaction: Transaction): void;
/**
* Fire a hook event for transaction finish.
* Expects to be given a transaction as the second argument.
*/
emit?(hook: '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 before sending an event.
* This is called right before an event is sent and should not be used to mutate the event.
* Expects to be given an Event & EventHint as the second/third argument.
*/
emit?(hook: 'beforeSendEvent', event: Event, hint?: EventHint): void;
/**
* Fire a hook event to process events before they are passed to (global) event processors.
* Expects to be given an Event & EventHint as the second/third argument.
*/
emit?(hook: 'preprocessEvent', event: Event, hint?: EventHint): 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;
/**
* Fire a hook for when a breadcrumb is added. Expects the breadcrumb as second argument.
*/
emit?(hook: 'beforeAddBreadcrumb', breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;
/**
* Fire a hook for when a DSC (Dynamic Sampling Context) is created. Expects the DSC as second argument.
*/
emit?(hook: 'createDsc', dsc: DynamicSamplingContext): void;
/**
* Fire a hook for when an OpenTelemetry span is ended (in @sentry/opentelemetry-node).
* Expects the OTEL span & as second argument, and an option object as third argument.
* The option argument may be mutated to drop the span.
*/
emit?(hook: 'otelSpanEnd', otelSpan: unknown, mutableOptions: { drop: boolean }): void;
/**
* Fire a hook event for after preparing a feedback event. Events to be given
* a feedback event as the second argument, and an optional options object as
* third argument.
*/
emit?(hook: 'beforeSendFeedback', feedback: FeedbackEvent, options?: { includeReplay?: boolean }): void;
/* eslint-enable @typescript-eslint/unified-signatures */
}