UNPKG

10.1 kBTypeScriptView Raw
1import type { Breadcrumb, BreadcrumbHint, CaptureContext, CheckIn, Client, CustomSamplingContext, Event, EventHint, Extra, Extras, MonitorConfig, Primitive, Scope as ScopeInterface, Session, SessionContext, Severity, SeverityLevel, Span, TransactionContext, User } from '@sentry/types';
2import type { Hub } from './hub';
3import type { Scope } from './scope';
4import type { ExclusiveEventHintOrCaptureContext } from './utils/prepareEvent';
5/**
6 * Captures an exception event and sends it to Sentry.
7 *
8 * @param exception The exception to capture.
9 * @param hint Optional additional data to attach to the Sentry event.
10 * @returns the id of the captured Sentry event.
11 */
12export declare function captureException(exception: any, hint?: ExclusiveEventHintOrCaptureContext): string;
13/**
14 * Captures a message event and sends it to Sentry.
15 *
16 * @param exception The exception to capture.
17 * @param captureContext Define the level of the message or pass in additional data to attach to the message.
18 * @returns the id of the captured message.
19 */
20export declare function captureMessage(message: string, captureContext?: CaptureContext | Severity | SeverityLevel): string;
21/**
22 * Captures a manually created event and sends it to Sentry.
23 *
24 * @param exception The event to send to Sentry.
25 * @param hint Optional additional data to attach to the Sentry event.
26 * @returns the id of the captured event.
27 */
28export declare function captureEvent(event: Event, hint?: EventHint): string;
29/**
30 * Callback to set context information onto the scope.
31 * @param callback Callback function that receives Scope.
32 *
33 * @deprecated Use getCurrentScope() directly.
34 */
35export declare function configureScope(callback: (scope: Scope) => void): ReturnType<Hub['configureScope']>;
36/**
37 * Records a new breadcrumb which will be attached to future events.
38 *
39 * Breadcrumbs will be added to subsequent events to provide more context on
40 * user's actions prior to an error or crash.
41 *
42 * @param breadcrumb The breadcrumb to record.
43 */
44export declare function addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): ReturnType<Hub['addBreadcrumb']>;
45/**
46 * Sets context data with the given name.
47 * @param name of the context
48 * @param context Any kind of data. This data will be normalized.
49 */
50export declare function setContext(name: string, context: {
51 [key: string]: any;
52} | null): ReturnType<Hub['setContext']>;
53/**
54 * Set an object that will be merged sent as extra data with the event.
55 * @param extras Extras object to merge into current context.
56 */
57export declare function setExtras(extras: Extras): ReturnType<Hub['setExtras']>;
58/**
59 * Set key:value that will be sent as extra data with the event.
60 * @param key String of extra
61 * @param extra Any kind of data. This data will be normalized.
62 */
63export declare function setExtra(key: string, extra: Extra): ReturnType<Hub['setExtra']>;
64/**
65 * Set an object that will be merged sent as tags data with the event.
66 * @param tags Tags context object to merge into current context.
67 */
68export declare function setTags(tags: {
69 [key: string]: Primitive;
70}): ReturnType<Hub['setTags']>;
71/**
72 * Set key:value that will be sent as tags data with the event.
73 *
74 * Can also be used to unset a tag, by passing `undefined`.
75 *
76 * @param key String key of tag
77 * @param value Value of tag
78 */
79export declare function setTag(key: string, value: Primitive): ReturnType<Hub['setTag']>;
80/**
81 * Updates user context information for future events.
82 *
83 * @param user User context object to be set in the current context. Pass `null` to unset the user.
84 */
85export declare function setUser(user: User | null): ReturnType<Hub['setUser']>;
86/**
87 * Creates a new scope with and executes the given operation within.
88 * The scope is automatically removed once the operation
89 * finishes or throws.
90 *
91 * This is essentially a convenience function for:
92 *
93 * pushScope();
94 * callback();
95 * popScope();
96 */
97export declare function withScope<T>(callback: (scope: Scope) => T): T;
98/**
99 * Set the given scope as the active scope in the callback.
100 */
101export declare function withScope<T>(scope: ScopeInterface | undefined, callback: (scope: Scope) => T): T;
102/**
103 * Attempts to fork the current isolation scope and the current scope based on the current async context strategy. If no
104 * async context strategy is set, the isolation scope and the current scope will not be forked (this is currently the
105 * case, for example, in the browser).
106 *
107 * Usage of this function in environments without async context strategy is discouraged and may lead to unexpected behaviour.
108 *
109 * This function is intended for Sentry SDK and SDK integration development. It is not recommended to be used in "normal"
110 * applications directly because it comes with pitfalls. Use at your own risk!
111 *
112 * @param callback The callback in which the passed isolation scope is active. (Note: In environments without async
113 * context strategy, the currently active isolation scope may change within execution of the callback.)
114 * @returns The same value that `callback` returns.
115 */
116export declare function withIsolationScope<T>(callback: (isolationScope: Scope) => T): T;
117/**
118 * Forks the current scope and sets the provided span as active span in the context of the provided callback.
119 *
120 * @param span Spans started in the context of the provided callback will be children of this span.
121 * @param callback Execution context in which the provided span will be active. Is passed the newly forked scope.
122 * @returns the value returned from the provided callback function.
123 */
124export declare function withActiveSpan<T>(span: Span, callback: (scope: Scope) => T): T;
125/**
126 * Starts a new `Transaction` and returns it. This is the entry point to manual tracing instrumentation.
127 *
128 * A tree structure can be built by adding child spans to the transaction, and child spans to other spans. To start a
129 * new child span within the transaction or any span, call the respective `.startChild()` method.
130 *
131 * Every child span must be finished before the transaction is finished, otherwise the unfinished spans are discarded.
132 *
133 * The transaction must be finished with a call to its `.end()` method, at which point the transaction with all its
134 * finished child spans will be sent to Sentry.
135 *
136 * NOTE: This function should only be used for *manual* instrumentation. Auto-instrumentation should call
137 * `startTransaction` directly on the hub.
138 *
139 * @param context Properties of the new `Transaction`.
140 * @param customSamplingContext Information given to the transaction sampling function (along with context-dependent
141 * default values). See {@link Options.tracesSampler}.
142 *
143 * @returns The transaction which was just started
144 *
145 * @deprecated Use `startSpan()`, `startSpanManual()` or `startInactiveSpan()` instead.
146 */
147export declare function startTransaction(context: TransactionContext, customSamplingContext?: CustomSamplingContext): ReturnType<Hub['startTransaction']>;
148/**
149 * Create a cron monitor check in and send it to Sentry.
150 *
151 * @param checkIn An object that describes a check in.
152 * @param upsertMonitorConfig An optional object that describes a monitor config. Use this if you want
153 * to create a monitor automatically when sending a check in.
154 */
155export declare function captureCheckIn(checkIn: CheckIn, upsertMonitorConfig?: MonitorConfig): string;
156/**
157 * Wraps a callback with a cron monitor check in. The check in will be sent to Sentry when the callback finishes.
158 *
159 * @param monitorSlug The distinct slug of the monitor.
160 * @param upsertMonitorConfig An optional object that describes a monitor config. Use this if you want
161 * to create a monitor automatically when sending a check in.
162 */
163export declare function withMonitor<T>(monitorSlug: CheckIn['monitorSlug'], callback: () => T, upsertMonitorConfig?: MonitorConfig): T;
164/**
165 * Call `flush()` on the current client, if there is one. See {@link Client.flush}.
166 *
167 * @param timeout Maximum time in ms the client should wait to flush its event queue. Omitting this parameter will cause
168 * the client to wait until all events are sent before resolving the promise.
169 * @returns A promise which resolves to `true` if the queue successfully drains before the timeout, or `false` if it
170 * doesn't (or if there's no client defined).
171 */
172export declare function flush(timeout?: number): Promise<boolean>;
173/**
174 * Call `close()` on the current client, if there is one. See {@link Client.close}.
175 *
176 * @param timeout Maximum time in ms the client should wait to flush its event queue before shutting down. Omitting this
177 * parameter will cause the client to wait until all events are sent before disabling itself.
178 * @returns A promise which resolves to `true` if the queue successfully drains before the timeout, or `false` if it
179 * doesn't (or if there's no client defined).
180 */
181export declare function close(timeout?: number): Promise<boolean>;
182/**
183 * This is the getter for lastEventId.
184 *
185 * @returns The last event id of a captured event.
186 * @deprecated This function will be removed in the next major version of the Sentry SDK.
187 */
188export declare function lastEventId(): string | undefined;
189/**
190 * Get the currently active client.
191 */
192export declare function getClient<C extends Client>(): C | undefined;
193/**
194 * Returns true if Sentry has been properly initialized.
195 */
196export declare function isInitialized(): boolean;
197/**
198 * Get the currently active scope.
199 */
200export declare function getCurrentScope(): Scope;
201/**
202 * Start a session on the current isolation scope.
203 *
204 * @param context (optional) additional properties to be applied to the returned session object
205 *
206 * @returns the new active session
207 */
208export declare function startSession(context?: SessionContext): Session;
209/**
210 * End the session on the current isolation scope.
211 */
212export declare function endSession(): void;
213/**
214 * Sends the current session on the scope to Sentry
215 *
216 * @param end If set the session will be marked as exited and removed from the scope.
217 * Defaults to `false`.
218 */
219export declare function captureSession(end?: boolean): void;
220//# sourceMappingURL=exports.d.ts.map
\No newline at end of file