UNPKG

13.3 kBTypeScriptView Raw
1import type { Breadcrumb, BreadcrumbHint } from './breadcrumb';
2import type { CheckIn, MonitorConfig } from './checkin';
3import type { EventDropReason } from './clientreport';
4import type { DataCategory } from './datacategory';
5import type { DsnComponents } from './dsn';
6import type { DynamicSamplingContext, Envelope } from './envelope';
7import type { Event, EventHint } from './event';
8import type { EventProcessor } from './eventprocessor';
9import type { FeedbackEvent } from './feedback';
10import type { Integration, IntegrationClass } from './integration';
11import type { MetricBucketItem } from './metrics';
12import type { ClientOptions } from './options';
13import type { ParameterizedString } from './parameterize';
14import type { Scope } from './scope';
15import type { SdkMetadata } from './sdkmetadata';
16import type { Session, SessionAggregates } from './session';
17import type { Severity, SeverityLevel } from './severity';
18import type { StartSpanOptions } from './startSpanOptions';
19import type { Transaction } from './transaction';
20import type { Transport, TransportMakeRequestResponse } from './transport';
21/**
22 * User-Facing Sentry SDK Client.
23 *
24 * This interface contains all methods to interface with the SDK once it has
25 * been installed. It allows to send events to Sentry, record breadcrumbs and
26 * set a context included in every event. Since the SDK mutates its environment,
27 * there will only be one instance during runtime.
28 *
29 */
30export interface Client<O extends ClientOptions = ClientOptions> {
31 /**
32 * Captures an exception event and sends it to Sentry.
33 *
34 * @param exception An exception-like object.
35 * @param hint May contain additional information about the original exception.
36 * @param scope An optional scope containing event metadata.
37 * @returns The event id
38 */
39 captureException(exception: any, hint?: EventHint, scope?: Scope): string | undefined;
40 /**
41 * Captures a message event and sends it to Sentry.
42 *
43 * @param message The message to send to Sentry.
44 * @param level Define the level of the message.
45 * @param hint May contain additional information about the original exception.
46 * @param scope An optional scope containing event metadata.
47 * @returns The event id
48 */
49 captureMessage(message: string, level?: Severity | SeverityLevel, hint?: EventHint, scope?: Scope): string | undefined;
50 /**
51 * Captures a manually created event and sends it to Sentry.
52 *
53 * @param event The event to send to Sentry.
54 * @param hint May contain additional information about the original exception.
55 * @param scope An optional scope containing event metadata.
56 * @returns The event id
57 */
58 captureEvent(event: Event, hint?: EventHint, scope?: Scope): string | undefined;
59 /**
60 * Captures a session
61 *
62 * @param session Session to be delivered
63 */
64 captureSession?(session: Session): void;
65 /**
66 * Create a cron monitor check in and send it to Sentry. This method is not available on all clients.
67 *
68 * @param checkIn An object that describes a check in.
69 * @param upsertMonitorConfig An optional object that describes a monitor config. Use this if you want
70 * to create a monitor automatically when sending a check in.
71 * @param scope An optional scope containing event metadata.
72 * @returns A string representing the id of the check in.
73 */
74 captureCheckIn?(checkIn: CheckIn, monitorConfig?: MonitorConfig, scope?: Scope): string;
75 /** Returns the current Dsn. */
76 getDsn(): DsnComponents | undefined;
77 /** Returns the current options. */
78 getOptions(): O;
79 /**
80 * @inheritdoc
81 *
82 * TODO (v8): Make this a required method.
83 */
84 getSdkMetadata?(): SdkMetadata | undefined;
85 /**
86 * Returns the transport that is used by the client.
87 * Please note that the transport gets lazy initialized so it will only be there once the first event has been sent.
88 *
89 * @returns The transport.
90 */
91 getTransport(): Transport | undefined;
92 /**
93 * Flush the event queue and set the client to `enabled = false`. See {@link Client.flush}.
94 *
95 * @param timeout Maximum time in ms the client should wait before shutting down. Omitting this parameter will cause
96 * the client to wait until all events are sent before disabling itself.
97 * @returns A promise which resolves to `true` if the flush completes successfully before the timeout, or `false` if
98 * it doesn't.
99 */
100 close(timeout?: number): PromiseLike<boolean>;
101 /**
102 * Wait for all events to be sent or the timeout to expire, whichever comes first.
103 *
104 * @param timeout Maximum time in ms the client should wait for events to be flushed. Omitting this parameter will
105 * cause the client to wait until all events are sent before resolving the promise.
106 * @returns A promise that will resolve with `true` if all events are sent before the timeout, or `false` if there are
107 * still events in the queue when the timeout is reached.
108 */
109 flush(timeout?: number): PromiseLike<boolean>;
110 /**
111 * Adds an event processor that applies to any event processed by this client.
112 *
113 * TODO (v8): Make this a required method.
114 */
115 addEventProcessor?(eventProcessor: EventProcessor): void;
116 /**
117 * Get all added event processors for this client.
118 *
119 * TODO (v8): Make this a required method.
120 */
121 getEventProcessors?(): EventProcessor[];
122 /**
123 * Returns the client's instance of the given integration class, it any.
124 * @deprecated Use `getIntegrationByName()` instead.
125 */
126 getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;
127 /** Get the instance of the integration with the given name on the client, if it was added. */
128 getIntegrationByName?<T extends Integration = Integration>(name: string): T | undefined;
129 /**
130 * Add an integration to the client.
131 * This can be used to e.g. lazy load integrations.
132 * In most cases, this should not be necessary, and you're better off just passing the integrations via `integrations: []` at initialization time.
133 * However, if you find the need to conditionally load & add an integration, you can use `addIntegration` to do so.
134 *
135 * TODO (v8): Make this a required method.
136 * */
137 addIntegration?(integration: Integration): void;
138 /**
139 * This is an internal function to setup all integrations that should run on the client.
140 * @deprecated Use `client.init()` instead.
141 */
142 setupIntegrations(forceInitialize?: boolean): void;
143 /**
144 * Initialize this client.
145 * Call this after the client was set on a scope.
146 */
147 init?(): void;
148 /** Creates an {@link Event} from all inputs to `captureException` and non-primitive inputs to `captureMessage`. */
149 eventFromException(exception: any, hint?: EventHint): PromiseLike<Event>;
150 /** Creates an {@link Event} from primitive inputs to `captureMessage`. */
151 eventFromMessage(message: ParameterizedString, level?: Severity | SeverityLevel, hint?: EventHint): PromiseLike<Event>;
152 /** Submits the event to Sentry */
153 sendEvent(event: Event, hint?: EventHint): void;
154 /** Submits the session to Sentry */
155 sendSession(session: Session | SessionAggregates): void;
156 /**
157 * Record on the client that an event got dropped (ie, an event that will not be sent to sentry).
158 *
159 * @param reason The reason why the event got dropped.
160 * @param category The data category of the dropped event.
161 * @param event The dropped event.
162 */
163 recordDroppedEvent(reason: EventDropReason, dataCategory: DataCategory, event?: Event): void;
164 /**
165 * Captures serialized metrics and sends them to Sentry.
166 *
167 * @experimental This API is experimental and might experience breaking changes
168 */
169 captureAggregateMetrics?(metricBucketItems: Array<MetricBucketItem>): void;
170 /**
171 * Register a callback for transaction start.
172 * Receives the transaction as argument.
173 */
174 on?(hook: 'startTransaction', callback: (transaction: Transaction) => void): void;
175 /**
176 * Register a callback for transaction finish.
177 * Receives the transaction as argument.
178 */
179 on?(hook: 'finishTransaction', callback: (transaction: Transaction) => void): void;
180 /**
181 * Register a callback for transaction start and finish.
182 */
183 on?(hook: 'beforeEnvelope', callback: (envelope: Envelope) => void): void;
184 /**
185 * Register a callback for before sending an event.
186 * This is called right before an event is sent and should not be used to mutate the event.
187 * Receives an Event & EventHint as arguments.
188 */
189 on?(hook: 'beforeSendEvent', callback: (event: Event, hint?: EventHint | undefined) => void): void;
190 /**
191 * Register a callback for preprocessing an event,
192 * before it is passed to (global) event processors.
193 * Receives an Event & EventHint as arguments.
194 */
195 on?(hook: 'preprocessEvent', callback: (event: Event, hint?: EventHint | undefined) => void): void;
196 /**
197 * Register a callback for when an event has been sent.
198 */
199 on?(hook: 'afterSendEvent', callback: (event: Event, sendResponse: TransportMakeRequestResponse | void) => void): void;
200 /**
201 * Register a callback before a breadcrumb is added.
202 */
203 on?(hook: 'beforeAddBreadcrumb', callback: (breadcrumb: Breadcrumb, hint?: BreadcrumbHint) => void): void;
204 /**
205 * Register a callback when a DSC (Dynamic Sampling Context) is created.
206 */
207 on?(hook: 'createDsc', callback: (dsc: DynamicSamplingContext) => void): void;
208 /**
209 * Register a callback when an OpenTelemetry span is ended (in @sentry/opentelemetry-node).
210 * The option argument may be mutated to drop the span.
211 */
212 on?(hook: 'otelSpanEnd', callback: (otelSpan: unknown, mutableOptions: {
213 drop: boolean;
214 }) => void): void;
215 /**
216 * Register a callback when a Feedback event has been prepared.
217 * This should be used to mutate the event. The options argument can hint
218 * about what kind of mutation it expects.
219 */
220 on?(hook: 'beforeSendFeedback', callback: (feedback: FeedbackEvent, options?: {
221 includeReplay?: boolean;
222 }) => void): void;
223 /**
224 * A hook for BrowserTracing to trigger a span start for a page load.
225 */
226 on?(hook: 'startPageLoadSpan', callback: (options: StartSpanOptions) => void): void;
227 /**
228 * A hook for BrowserTracing to trigger a span for a navigation.
229 */
230 on?(hook: 'startNavigationSpan', callback: (options: StartSpanOptions) => void): void;
231 /**
232 * Fire a hook event for transaction start.
233 * Expects to be given a transaction as the second argument.
234 */
235 emit?(hook: 'startTransaction', transaction: Transaction): void;
236 /**
237 * Fire a hook event for transaction finish.
238 * Expects to be given a transaction as the second argument.
239 */
240 emit?(hook: 'finishTransaction', transaction: Transaction): void;
241 emit?(hook: 'beforeEnvelope', envelope: Envelope): void;
242 /**
243 * Fire a hook event before sending an event.
244 * This is called right before an event is sent and should not be used to mutate the event.
245 * Expects to be given an Event & EventHint as the second/third argument.
246 */
247 emit?(hook: 'beforeSendEvent', event: Event, hint?: EventHint): void;
248 /**
249 * Fire a hook event to process events before they are passed to (global) event processors.
250 * Expects to be given an Event & EventHint as the second/third argument.
251 */
252 emit?(hook: 'preprocessEvent', event: Event, hint?: EventHint): void;
253 emit?(hook: 'afterSendEvent', event: Event, sendResponse: TransportMakeRequestResponse | void): void;
254 /**
255 * Fire a hook for when a breadcrumb is added. Expects the breadcrumb as second argument.
256 */
257 emit?(hook: 'beforeAddBreadcrumb', breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;
258 /**
259 * Fire a hook for when a DSC (Dynamic Sampling Context) is created. Expects the DSC as second argument.
260 */
261 emit?(hook: 'createDsc', dsc: DynamicSamplingContext): void;
262 /**
263 * Fire a hook for when an OpenTelemetry span is ended (in @sentry/opentelemetry-node).
264 * Expects the OTEL span & as second argument, and an option object as third argument.
265 * The option argument may be mutated to drop the span.
266 */
267 emit?(hook: 'otelSpanEnd', otelSpan: unknown, mutableOptions: {
268 drop: boolean;
269 }): void;
270 /**
271 * Fire a hook event for after preparing a feedback event. Events to be given
272 * a feedback event as the second argument, and an optional options object as
273 * third argument.
274 */
275 emit?(hook: 'beforeSendFeedback', feedback: FeedbackEvent, options?: {
276 includeReplay?: boolean;
277 }): void;
278 /**
279 * Emit a hook event for BrowserTracing to trigger a span start for a page load.
280 */
281 emit?(hook: 'startPageLoadSpan', options: StartSpanOptions): void;
282 /**
283 * Emit a hook event for BrowserTracing to trigger a span for a navigation.
284 */
285 emit?(hook: 'startNavigationSpan', options: StartSpanOptions): void;
286}
287//# sourceMappingURL=client.d.ts.map
\No newline at end of file