UNPKG

8.55 kBTypeScriptView Raw
1import type { Breadcrumb, BreadcrumbHint } from './breadcrumb';
2import type { Client } from './client';
3import type { Event, EventHint } from './event';
4import type { Extra, Extras } from './extra';
5import type { Integration, IntegrationClass } from './integration';
6import type { Primitive } from './misc';
7import type { Scope } from './scope';
8import type { Session } from './session';
9import type { Severity, SeverityLevel } from './severity';
10import type { CustomSamplingContext, Transaction, TransactionContext } from './transaction';
11import type { User } from './user';
12/**
13 * Internal class used to make sure we always have the latest internal functions
14 * working in case we have a version conflict.
15 */
16export interface Hub {
17 /**
18 * Checks if this hub's version is older than the given version.
19 *
20 * @param version A version number to compare to.
21 * @return True if the given version is newer; otherwise false.
22 *
23 * @hidden
24 */
25 isOlderThan(version: number): boolean;
26 /**
27 * This binds the given client to the current scope.
28 * @param client An SDK client (client) instance.
29 */
30 bindClient(client?: Client): void;
31 /**
32 * Create a new scope to store context information.
33 *
34 * The scope will be layered on top of the current one. It is isolated, i.e. all
35 * breadcrumbs and context information added to this scope will be removed once
36 * the scope ends. Be sure to always remove this scope with {@link this.popScope}
37 * when the operation finishes or throws.
38 *
39 * @returns Scope, the new cloned scope
40 */
41 pushScope(): Scope;
42 /**
43 * Removes a previously pushed scope from the stack.
44 *
45 * This restores the state before the scope was pushed. All breadcrumbs and
46 * context information added since the last call to {@link this.pushScope} are
47 * discarded.
48 */
49 popScope(): boolean;
50 /**
51 * Creates a new scope with and executes the given operation within.
52 * The scope is automatically removed once the operation
53 * finishes or throws.
54 *
55 * This is essentially a convenience function for:
56 *
57 * pushScope();
58 * callback();
59 * popScope();
60 *
61 * @param callback that will be enclosed into push/popScope.
62 */
63 withScope(callback: (scope: Scope) => void): void;
64 /** Returns the client of the top stack. */
65 getClient(): Client | undefined;
66 /**
67 * Captures an exception event and sends it to Sentry.
68 *
69 * @param exception An exception-like object.
70 * @param hint May contain additional information about the original exception.
71 * @returns The generated eventId.
72 */
73 captureException(exception: any, hint?: EventHint): string;
74 /**
75 * Captures a message event and sends it to Sentry.
76 *
77 * @param message The message to send to Sentry.
78 * @param level Define the level of the message.
79 * @param hint May contain additional information about the original exception.
80 * @returns The generated eventId.
81 */
82 captureMessage(message: string, level?: Severity | SeverityLevel, hint?: EventHint): string;
83 /**
84 * Captures a manually created event and sends it to Sentry.
85 *
86 * @param event The event to send to Sentry.
87 * @param hint May contain additional information about the original exception.
88 */
89 captureEvent(event: Event, hint?: EventHint): string;
90 /**
91 * This is the getter for lastEventId.
92 *
93 * @returns The last event id of a captured event.
94 */
95 lastEventId(): string | undefined;
96 /**
97 * Records a new breadcrumb which will be attached to future events.
98 *
99 * Breadcrumbs will be added to subsequent events to provide more context on
100 * user's actions prior to an error or crash.
101 *
102 * @param breadcrumb The breadcrumb to record.
103 * @param hint May contain additional information about the original breadcrumb.
104 */
105 addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;
106 /**
107 * Updates user context information for future events.
108 *
109 * @param user User context object to be set in the current context. Pass `null` to unset the user.
110 */
111 setUser(user: User | null): void;
112 /**
113 * Set an object that will be merged sent as tags data with the event.
114 *
115 * @param tags Tags context object to merge into current context.
116 */
117 setTags(tags: {
118 [key: string]: Primitive;
119 }): void;
120 /**
121 * Set key:value that will be sent as tags data with the event.
122 *
123 * Can also be used to unset a tag, by passing `undefined`.
124 *
125 * @param key String key of tag
126 * @param value Value of tag
127 */
128 setTag(key: string, value: Primitive): void;
129 /**
130 * Set key:value that will be sent as extra data with the event.
131 * @param key String of extra
132 * @param extra Any kind of data. This data will be normalized.
133 */
134 setExtra(key: string, extra: Extra): void;
135 /**
136 * Set an object that will be merged sent as extra data with the event.
137 * @param extras Extras object to merge into current context.
138 */
139 setExtras(extras: Extras): void;
140 /**
141 * Sets context data with the given name.
142 * @param name of the context
143 * @param context Any kind of data. This data will be normalized.
144 */
145 setContext(name: string, context: {
146 [key: string]: any;
147 } | null): void;
148 /**
149 * Callback to set context information onto the scope.
150 *
151 * @param callback Callback function that receives Scope.
152 */
153 configureScope(callback: (scope: Scope) => void): void;
154 /**
155 * For the duration of the callback, this hub will be set as the global current Hub.
156 * This function is useful if you want to run your own client and hook into an already initialized one
157 * e.g.: Reporting issues to your own sentry when running in your component while still using the users configuration.
158 */
159 run(callback: (hub: Hub) => void): void;
160 /** Returns the integration if installed on the current client. */
161 getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;
162 /** Returns all trace headers that are currently on the top scope. */
163 traceHeaders(): {
164 [key: string]: string;
165 };
166 /**
167 * Starts a new `Transaction` and returns it. This is the entry point to manual tracing instrumentation.
168 *
169 * A tree structure can be built by adding child spans to the transaction, and child spans to other spans. To start a
170 * new child span within the transaction or any span, call the respective `.startChild()` method.
171 *
172 * Every child span must be finished before the transaction is finished, otherwise the unfinished spans are discarded.
173 *
174 * The transaction must be finished with a call to its `.finish()` method, at which point the transaction with all its
175 * finished child spans will be sent to Sentry.
176 *
177 * @param context Properties of the new `Transaction`.
178 * @param customSamplingContext Information given to the transaction sampling function (along with context-dependent
179 * default values). See {@link Options.tracesSampler}.
180 *
181 * @returns The transaction which was just started
182 */
183 startTransaction(context: TransactionContext, customSamplingContext?: CustomSamplingContext): Transaction;
184 /**
185 * Starts a new `Session`, sets on the current scope and returns it.
186 *
187 * To finish a `session`, it has to be passed directly to `client.captureSession`, which is done automatically
188 * when using `hub.endSession()` for the session currently stored on the scope.
189 *
190 * When there's already an existing session on the scope, it'll be automatically ended.
191 *
192 * @param context Optional properties of the new `Session`.
193 *
194 * @returns The session which was just started
195 */
196 startSession(context?: Session): Session;
197 /**
198 * Ends the session that lives on the current scope and sends it to Sentry
199 */
200 endSession(): void;
201 /**
202 * Sends the current session on the scope to Sentry
203 * @param endSession If set the session will be marked as exited and removed from the scope
204 */
205 captureSession(endSession?: boolean): void;
206 /**
207 * Returns if default PII should be sent to Sentry and propagated in ourgoing requests
208 * when Tracing is used.
209 */
210 shouldSendDefaultPii(): boolean;
211}
212//# sourceMappingURL=hub.d.ts.map
\No newline at end of file