1 | import type { Breadcrumb, BreadcrumbHint, Client, CustomSamplingContext, Event, EventHint, Extra, Extras, Hub as HubInterface, Integration, IntegrationClass, Primitive, Session, SessionContext, Severity, SeverityLevel, Transaction, TransactionContext, User } from '@sentry/types';
|
2 | import { Scope } from './scope';
|
3 | /**
|
4 | * API compatibility version of this hub.
|
5 | *
|
6 | * WARNING: This number should only be increased when the global interface
|
7 | * changes and new methods are introduced.
|
8 | *
|
9 | * @hidden
|
10 | */
|
11 | export declare const API_VERSION: number;
|
12 | export interface RunWithAsyncContextOptions {
|
13 | /** Whether to reuse an existing async context if one exists. Defaults to false. */
|
14 | reuseExisting?: boolean;
|
15 | }
|
16 | /**
|
17 | * @private Private API with no semver guarantees!
|
18 | *
|
19 | * Strategy used to track async context.
|
20 | */
|
21 | export interface AsyncContextStrategy {
|
22 | /**
|
23 | * Gets the current async context. Returns undefined if there is no current async context.
|
24 | */
|
25 | getCurrentHub: () => Hub | undefined;
|
26 | /**
|
27 | * Runs the supplied callback in its own async context.
|
28 | */
|
29 | runWithAsyncContext<T>(callback: () => T, options: RunWithAsyncContextOptions): T;
|
30 | }
|
31 | /**
|
32 | * A layer in the process stack.
|
33 | * @hidden
|
34 | */
|
35 | export interface Layer {
|
36 | client?: Client;
|
37 | scope: Scope;
|
38 | }
|
39 | /**
|
40 | * An object that contains a hub and maintains a scope stack.
|
41 | * @hidden
|
42 | */
|
43 | export interface Carrier {
|
44 | __SENTRY__?: {
|
45 | hub?: Hub;
|
46 | acs?: AsyncContextStrategy;
|
47 | /**
|
48 | * Extra Hub properties injected by various SDKs
|
49 | */
|
50 | integrations?: Integration[];
|
51 | extensions?: {
|
52 | /** Extension methods for the hub, which are bound to the current Hub instance */
|
53 | [key: string]: Function;
|
54 | };
|
55 | };
|
56 | }
|
57 | /**
|
58 | * @deprecated The `Hub` class will be removed in version 8 of the SDK in favour of `Scope` and `Client` objects.
|
59 | *
|
60 | * If you previously used the `Hub` class directly, replace it with `Scope` and `Client` objects. More information:
|
61 | * - [Multiple Sentry Instances](https://docs.sentry.io/platforms/javascript/best-practices/multiple-sentry-instances/)
|
62 | * - [Browser Extensions](https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/)
|
63 | *
|
64 | * Some of our APIs are typed with the Hub class instead of the interface (e.g. `getCurrentHub`). Most of them are deprecated
|
65 | * themselves and will also be removed in version 8. More information:
|
66 | * - [Migration Guide](https://github.com/getsentry/sentry-javascript/blob/develop/MIGRATION.md#deprecate-hub)
|
67 | */
|
68 | export declare class Hub implements HubInterface {
|
69 | private readonly _version;
|
70 | /** Is a {@link Layer}[] containing the client and scope */
|
71 | private readonly _stack;
|
72 | /** Contains the last event id of a captured event. */
|
73 | private _lastEventId?;
|
74 | private _isolationScope;
|
75 | /**
|
76 | * Creates a new instance of the hub, will push one {@link Layer} into the
|
77 | * internal stack on creation.
|
78 | *
|
79 | * @param client bound to the hub.
|
80 | * @param scope bound to the hub.
|
81 | * @param version number, higher number means higher priority.
|
82 | *
|
83 | * @deprecated Instantiation of Hub objects is deprecated and the constructor will be removed in version 8 of the SDK.
|
84 | *
|
85 | * If you are currently using the Hub for multi-client use like so:
|
86 | *
|
87 | * ```
|
88 | * // OLD
|
89 | * const hub = new Hub();
|
90 | * hub.bindClient(client);
|
91 | * makeMain(hub)
|
92 | * ```
|
93 | *
|
94 | * instead initialize the client as follows:
|
95 | *
|
96 | * ```
|
97 | * // NEW
|
98 | * Sentry.withIsolationScope(() => {
|
99 | * Sentry.setCurrentClient(client);
|
100 | * client.init();
|
101 | * });
|
102 | * ```
|
103 | *
|
104 | * If you are using the Hub to capture events like so:
|
105 | *
|
106 | * ```
|
107 | * // OLD
|
108 | * const client = new Client();
|
109 | * const hub = new Hub(client);
|
110 | * hub.captureException()
|
111 | * ```
|
112 | *
|
113 | * instead capture isolated events as follows:
|
114 | *
|
115 | * ```
|
116 | * // NEW
|
117 | * const client = new Client();
|
118 | * const scope = new Scope();
|
119 | * scope.setClient(client);
|
120 | * scope.captureException();
|
121 | * ```
|
122 | */
|
123 | constructor(client?: Client, scope?: Scope, isolationScope?: Scope, _version?: number);
|
124 | /**
|
125 | * Checks if this hub's version is older than the given version.
|
126 | *
|
127 | * @param version A version number to compare to.
|
128 | * @return True if the given version is newer; otherwise false.
|
129 | *
|
130 | * @deprecated This will be removed in v8.
|
131 | */
|
132 | isOlderThan(version: number): boolean;
|
133 | /**
|
134 | * This binds the given client to the current scope.
|
135 | * @param client An SDK client (client) instance.
|
136 | *
|
137 | * @deprecated Use `initAndBind()` directly, or `setCurrentClient()` and/or `client.init()` instead.
|
138 | */
|
139 | bindClient(client?: Client): void;
|
140 | /**
|
141 | * @inheritDoc
|
142 | *
|
143 | * @deprecated Use `withScope` instead.
|
144 | */
|
145 | pushScope(): Scope;
|
146 | /**
|
147 | * @inheritDoc
|
148 | *
|
149 | * @deprecated Use `withScope` instead.
|
150 | */
|
151 | popScope(): boolean;
|
152 | /**
|
153 | * @inheritDoc
|
154 | *
|
155 | * @deprecated Use `Sentry.withScope()` instead.
|
156 | */
|
157 | withScope<T>(callback: (scope: Scope) => T): T;
|
158 | /**
|
159 | * @inheritDoc
|
160 | *
|
161 | * @deprecated Use `Sentry.getClient()` instead.
|
162 | */
|
163 | getClient<C extends Client>(): C | undefined;
|
164 | /**
|
165 | * Returns the scope of the top stack.
|
166 | *
|
167 | * @deprecated Use `Sentry.getCurrentScope()` instead.
|
168 | */
|
169 | getScope(): Scope;
|
170 | /**
|
171 | * @deprecated Use `Sentry.getIsolationScope()` instead.
|
172 | */
|
173 | getIsolationScope(): Scope;
|
174 | /**
|
175 | * Returns the scope stack for domains or the process.
|
176 | * @deprecated This will be removed in v8.
|
177 | */
|
178 | getStack(): Layer[];
|
179 | /**
|
180 | * Returns the topmost scope layer in the order domain > local > process.
|
181 | * @deprecated This will be removed in v8.
|
182 | */
|
183 | getStackTop(): Layer;
|
184 | /**
|
185 | * @inheritDoc
|
186 | *
|
187 | * @deprecated Use `Sentry.captureException()` instead.
|
188 | */
|
189 | captureException(exception: unknown, hint?: EventHint): string;
|
190 | /**
|
191 | * @inheritDoc
|
192 | *
|
193 | * @deprecated Use `Sentry.captureMessage()` instead.
|
194 | */
|
195 | captureMessage(message: string, level?: Severity | SeverityLevel, hint?: EventHint): string;
|
196 | /**
|
197 | * @inheritDoc
|
198 | *
|
199 | * @deprecated Use `Sentry.captureEvent()` instead.
|
200 | */
|
201 | captureEvent(event: Event, hint?: EventHint): string;
|
202 | /**
|
203 | * @inheritDoc
|
204 | *
|
205 | * @deprecated This will be removed in v8.
|
206 | */
|
207 | lastEventId(): string | undefined;
|
208 | /**
|
209 | * @inheritDoc
|
210 | *
|
211 | * @deprecated Use `Sentry.addBreadcrumb()` instead.
|
212 | */
|
213 | addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;
|
214 | /**
|
215 | * @inheritDoc
|
216 | * @deprecated Use `Sentry.setUser()` instead.
|
217 | */
|
218 | setUser(user: User | null): void;
|
219 | /**
|
220 | * @inheritDoc
|
221 | * @deprecated Use `Sentry.setTags()` instead.
|
222 | */
|
223 | setTags(tags: {
|
224 | [key: string]: Primitive;
|
225 | }): void;
|
226 | /**
|
227 | * @inheritDoc
|
228 | * @deprecated Use `Sentry.setExtras()` instead.
|
229 | */
|
230 | setExtras(extras: Extras): void;
|
231 | /**
|
232 | * @inheritDoc
|
233 | * @deprecated Use `Sentry.setTag()` instead.
|
234 | */
|
235 | setTag(key: string, value: Primitive): void;
|
236 | /**
|
237 | * @inheritDoc
|
238 | * @deprecated Use `Sentry.setExtra()` instead.
|
239 | */
|
240 | setExtra(key: string, extra: Extra): void;
|
241 | /**
|
242 | * @inheritDoc
|
243 | * @deprecated Use `Sentry.setContext()` instead.
|
244 | */
|
245 | setContext(name: string, context: {
|
246 | [key: string]: any;
|
247 | } | null): void;
|
248 | /**
|
249 | * @inheritDoc
|
250 | *
|
251 | * @deprecated Use `getScope()` directly.
|
252 | */
|
253 | configureScope(callback: (scope: Scope) => void): void;
|
254 | /**
|
255 | * @inheritDoc
|
256 | */
|
257 | run(callback: (hub: Hub) => void): void;
|
258 | /**
|
259 | * @inheritDoc
|
260 | * @deprecated Use `Sentry.getClient().getIntegrationByName()` instead.
|
261 | */
|
262 | getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;
|
263 | /**
|
264 | * Starts a new `Transaction` and returns it. This is the entry point to manual tracing instrumentation.
|
265 | *
|
266 | * A tree structure can be built by adding child spans to the transaction, and child spans to other spans. To start a
|
267 | * new child span within the transaction or any span, call the respective `.startChild()` method.
|
268 | *
|
269 | * Every child span must be finished before the transaction is finished, otherwise the unfinished spans are discarded.
|
270 | *
|
271 | * The transaction must be finished with a call to its `.end()` method, at which point the transaction with all its
|
272 | * finished child spans will be sent to Sentry.
|
273 | *
|
274 | * @param context Properties of the new `Transaction`.
|
275 | * @param customSamplingContext Information given to the transaction sampling function (along with context-dependent
|
276 | * default values). See {@link Options.tracesSampler}.
|
277 | *
|
278 | * @returns The transaction which was just started
|
279 | *
|
280 | * @deprecated Use `startSpan()`, `startSpanManual()` or `startInactiveSpan()` instead.
|
281 | */
|
282 | startTransaction(context: TransactionContext, customSamplingContext?: CustomSamplingContext): Transaction;
|
283 | /**
|
284 | * @inheritDoc
|
285 | * @deprecated Use `spanToTraceHeader()` instead.
|
286 | */
|
287 | traceHeaders(): {
|
288 | [key: string]: string;
|
289 | };
|
290 | /**
|
291 | * @inheritDoc
|
292 | *
|
293 | * @deprecated Use top level `captureSession` instead.
|
294 | */
|
295 | captureSession(endSession?: boolean): void;
|
296 | /**
|
297 | * @inheritDoc
|
298 | * @deprecated Use top level `endSession` instead.
|
299 | */
|
300 | endSession(): void;
|
301 | /**
|
302 | * @inheritDoc
|
303 | * @deprecated Use top level `startSession` instead.
|
304 | */
|
305 | startSession(context?: SessionContext): Session;
|
306 | /**
|
307 | * Returns if default PII should be sent to Sentry and propagated in ourgoing requests
|
308 | * when Tracing is used.
|
309 | *
|
310 | * @deprecated Use top-level `getClient().getOptions().sendDefaultPii` instead. This function
|
311 | * only unnecessarily increased API surface but only wrapped accessing the option.
|
312 | */
|
313 | shouldSendDefaultPii(): boolean;
|
314 | /**
|
315 | * Sends the current Session on the scope
|
316 | */
|
317 | private _sendSessionUpdate;
|
318 | /**
|
319 | * Calls global extension method and binding current instance to the function call
|
320 | */
|
321 | private _callExtensionMethod;
|
322 | }
|
323 | /**
|
324 | * Returns the global shim registry.
|
325 | *
|
326 | * FIXME: This function is problematic, because despite always returning a valid Carrier,
|
327 | * it has an optional `__SENTRY__` property, which then in turn requires us to always perform an unnecessary check
|
328 | * at the call-site. We always access the carrier through this function, so we can guarantee that `__SENTRY__` is there.
|
329 | **/
|
330 | export declare function getMainCarrier(): Carrier;
|
331 | /**
|
332 | * Replaces the current main hub with the passed one on the global object
|
333 | *
|
334 | * @returns The old replaced hub
|
335 | *
|
336 | * @deprecated Use `setCurrentClient()` instead.
|
337 | */
|
338 | export declare function makeMain(hub: Hub): Hub;
|
339 | /**
|
340 | * Returns the default hub instance.
|
341 | *
|
342 | * If a hub is already registered in the global carrier but this module
|
343 | * contains a more recent version, it replaces the registered version.
|
344 | * Otherwise, the currently registered hub will be returned.
|
345 | *
|
346 | * @deprecated Use the respective replacement method directly instead.
|
347 | */
|
348 | export declare function getCurrentHub(): Hub;
|
349 | /**
|
350 | * Get the currently active isolation scope.
|
351 | * The isolation scope is active for the current exection context,
|
352 | * meaning that it will remain stable for the same Hub.
|
353 | */
|
354 | export declare function getIsolationScope(): Scope;
|
355 | /**
|
356 | * @private Private API with no semver guarantees!
|
357 | *
|
358 | * If the carrier does not contain a hub, a new hub is created with the global hub client and scope.
|
359 | */
|
360 | export declare function ensureHubOnCarrier(carrier: Carrier, parent?: Hub): void;
|
361 | /**
|
362 | * @private Private API with no semver guarantees!
|
363 | *
|
364 | * Sets the global async context strategy
|
365 | */
|
366 | export declare function setAsyncContextStrategy(strategy: AsyncContextStrategy | undefined): void;
|
367 | /**
|
368 | * Runs the supplied callback in its own async context. Async Context strategies are defined per SDK.
|
369 | *
|
370 | * @param callback The callback to run in its own async context
|
371 | * @param options Options to pass to the async context strategy
|
372 | * @returns The result of the callback
|
373 | */
|
374 | export declare function runWithAsyncContext<T>(callback: () => T, options?: RunWithAsyncContextOptions): T;
|
375 | /**
|
376 | * This will create a new {@link Hub} and add to the passed object on
|
377 | * __SENTRY__.hub.
|
378 | * @param carrier object
|
379 | * @hidden
|
380 | */
|
381 | export declare function getHubFromCarrier(carrier: Carrier): Hub;
|
382 | /**
|
383 | * This will set passed {@link Hub} on the passed object's __SENTRY__.hub attribute
|
384 | * @param carrier object
|
385 | * @param hub Hub
|
386 | * @returns A boolean indicating success or failure
|
387 | */
|
388 | export declare function setHubOnCarrier(carrier: Carrier, hub: Hub): boolean;
|
389 | //# sourceMappingURL=hub.d.ts.map |
\ | No newline at end of file |