UNPKG

7.79 kBTypeScriptView Raw
1import 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';
2import { 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 */
11export declare const API_VERSION = 4;
12export 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 */
21export 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 */
35export 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 */
43export 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 * @inheritDoc
59 */
60export declare class Hub implements HubInterface {
61 private readonly _version;
62 /** Is a {@link Layer}[] containing the client and scope */
63 private readonly _stack;
64 /** Contains the last event id of a captured event. */
65 private _lastEventId?;
66 /**
67 * Creates a new instance of the hub, will push one {@link Layer} into the
68 * internal stack on creation.
69 *
70 * @param client bound to the hub.
71 * @param scope bound to the hub.
72 * @param version number, higher number means higher priority.
73 */
74 constructor(client?: Client, scope?: Scope, _version?: number);
75 /**
76 * @inheritDoc
77 */
78 isOlderThan(version: number): boolean;
79 /**
80 * @inheritDoc
81 */
82 bindClient(client?: Client): void;
83 /**
84 * @inheritDoc
85 */
86 pushScope(): Scope;
87 /**
88 * @inheritDoc
89 */
90 popScope(): boolean;
91 /**
92 * @inheritDoc
93 */
94 withScope(callback: (scope: Scope) => void): void;
95 /**
96 * @inheritDoc
97 */
98 getClient<C extends Client>(): C | undefined;
99 /** Returns the scope of the top stack. */
100 getScope(): Scope;
101 /** Returns the scope stack for domains or the process. */
102 getStack(): Layer[];
103 /** Returns the topmost scope layer in the order domain > local > process. */
104 getStackTop(): Layer;
105 /**
106 * @inheritDoc
107 */
108 captureException(exception: unknown, hint?: EventHint): string;
109 /**
110 * @inheritDoc
111 */
112 captureMessage(message: string, level?: Severity | SeverityLevel, hint?: EventHint): string;
113 /**
114 * @inheritDoc
115 */
116 captureEvent(event: Event, hint?: EventHint): string;
117 /**
118 * @inheritDoc
119 */
120 lastEventId(): string | undefined;
121 /**
122 * @inheritDoc
123 */
124 addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;
125 /**
126 * @inheritDoc
127 */
128 setUser(user: User | null): void;
129 /**
130 * @inheritDoc
131 */
132 setTags(tags: {
133 [key: string]: Primitive;
134 }): void;
135 /**
136 * @inheritDoc
137 */
138 setExtras(extras: Extras): void;
139 /**
140 * @inheritDoc
141 */
142 setTag(key: string, value: Primitive): void;
143 /**
144 * @inheritDoc
145 */
146 setExtra(key: string, extra: Extra): void;
147 /**
148 * @inheritDoc
149 */
150 setContext(name: string, context: {
151 [key: string]: any;
152 } | null): void;
153 /**
154 * @inheritDoc
155 */
156 configureScope(callback: (scope: Scope) => void): void;
157 /**
158 * @inheritDoc
159 */
160 run(callback: (hub: Hub) => void): void;
161 /**
162 * @inheritDoc
163 */
164 getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;
165 /**
166 * @inheritDoc
167 */
168 startTransaction(context: TransactionContext, customSamplingContext?: CustomSamplingContext): Transaction;
169 /**
170 * @inheritDoc
171 */
172 traceHeaders(): {
173 [key: string]: string;
174 };
175 /**
176 * @inheritDoc
177 */
178 captureSession(endSession?: boolean): void;
179 /**
180 * @inheritDoc
181 */
182 endSession(): void;
183 /**
184 * @inheritDoc
185 */
186 startSession(context?: SessionContext): Session;
187 /**
188 * Returns if default PII should be sent to Sentry and propagated in ourgoing requests
189 * when Tracing is used.
190 */
191 shouldSendDefaultPii(): boolean;
192 /**
193 * Sends the current Session on the scope
194 */
195 private _sendSessionUpdate;
196 /**
197 * Internal helper function to call a method on the top client if it exists.
198 *
199 * @param method The method to call on the client.
200 * @param args Arguments to pass to the client function.
201 */
202 private _withClient;
203 /**
204 * Calls global extension method and binding current instance to the function call
205 */
206 private _callExtensionMethod;
207}
208/**
209 * Returns the global shim registry.
210 *
211 * FIXME: This function is problematic, because despite always returning a valid Carrier,
212 * it has an optional `__SENTRY__` property, which then in turn requires us to always perform an unnecessary check
213 * at the call-site. We always access the carrier through this function, so we can guarantee that `__SENTRY__` is there.
214 **/
215export declare function getMainCarrier(): Carrier;
216/**
217 * Replaces the current main hub with the passed one on the global object
218 *
219 * @returns The old replaced hub
220 */
221export declare function makeMain(hub: Hub): Hub;
222/**
223 * Returns the default hub instance.
224 *
225 * If a hub is already registered in the global carrier but this module
226 * contains a more recent version, it replaces the registered version.
227 * Otherwise, the currently registered hub will be returned.
228 */
229export declare function getCurrentHub(): Hub;
230/**
231 * @private Private API with no semver guarantees!
232 *
233 * If the carrier does not contain a hub, a new hub is created with the global hub client and scope.
234 */
235export declare function ensureHubOnCarrier(carrier: Carrier, parent?: Hub): void;
236/**
237 * @private Private API with no semver guarantees!
238 *
239 * Sets the global async context strategy
240 */
241export declare function setAsyncContextStrategy(strategy: AsyncContextStrategy | undefined): void;
242/**
243 * Runs the supplied callback in its own async context. Async Context strategies are defined per SDK.
244 *
245 * @param callback The callback to run in its own async context
246 * @param options Options to pass to the async context strategy
247 * @returns The result of the callback
248 */
249export declare function runWithAsyncContext<T>(callback: () => T, options?: RunWithAsyncContextOptions): T;
250/**
251 * This will create a new {@link Hub} and add to the passed object on
252 * __SENTRY__.hub.
253 * @param carrier object
254 * @hidden
255 */
256export declare function getHubFromCarrier(carrier: Carrier): Hub;
257/**
258 * This will set passed {@link Hub} on the passed object's __SENTRY__.hub attribute
259 * @param carrier object
260 * @param hub Hub
261 * @returns A boolean indicating success or failure
262 */
263export declare function setHubOnCarrier(carrier: Carrier, hub: Hub): boolean;
264//# sourceMappingURL=hub.d.ts.map
\No newline at end of file