UNPKG

6.86 kBTypeScriptView Raw
1import { Breadcrumb, BreadcrumbHint, Client, CustomSamplingContext, Event, EventHint, Extra, Extras, Hub as HubInterface, Integration, IntegrationClass, Primitive, SessionContext, Severity, Span, SpanContext, Transaction, TransactionContext, User } from '@sentry/types';
2import { Scope } from './scope';
3import { Session } from './session';
4/**
5 * API compatibility version of this hub.
6 *
7 * WARNING: This number should only be increased when the global interface
8 * changes and new methods are introduced.
9 *
10 * @hidden
11 */
12export declare const API_VERSION = 4;
13/**
14 * A layer in the process stack.
15 * @hidden
16 */
17export interface Layer {
18 client?: Client;
19 scope?: Scope;
20}
21/**
22 * An object that contains a hub and maintains a scope stack.
23 * @hidden
24 */
25export interface Carrier {
26 __SENTRY__?: {
27 hub?: Hub;
28 /**
29 * Extra Hub properties injected by various SDKs
30 */
31 integrations?: Integration[];
32 extensions?: {
33 /** Hack to prevent bundlers from breaking our usage of the domain package in the cross-platform Hub package */
34 domain?: {
35 [key: string]: any;
36 };
37 } & {
38 /** Extension methods for the hub, which are bound to the current Hub instance */
39 [key: string]: Function;
40 };
41 };
42}
43/**
44 * @hidden
45 * @deprecated Can be removed once `Hub.getActiveDomain` is removed.
46 */
47export interface DomainAsCarrier extends Carrier {
48 members: {
49 [key: string]: any;
50 }[];
51}
52/**
53 * @inheritDoc
54 */
55export declare class Hub implements HubInterface {
56 private readonly _version;
57 /** Is a {@link Layer}[] containing the client and scope */
58 private readonly _stack;
59 /** Contains the last event id of a captured event. */
60 private _lastEventId?;
61 /**
62 * Creates a new instance of the hub, will push one {@link Layer} into the
63 * internal stack on creation.
64 *
65 * @param client bound to the hub.
66 * @param scope bound to the hub.
67 * @param version number, higher number means higher priority.
68 */
69 constructor(client?: Client, scope?: Scope, _version?: number);
70 /**
71 * @inheritDoc
72 */
73 isOlderThan(version: number): boolean;
74 /**
75 * @inheritDoc
76 */
77 bindClient(client?: Client): void;
78 /**
79 * @inheritDoc
80 */
81 pushScope(): Scope;
82 /**
83 * @inheritDoc
84 */
85 popScope(): boolean;
86 /**
87 * @inheritDoc
88 */
89 withScope(callback: (scope: Scope) => void): void;
90 /**
91 * @inheritDoc
92 */
93 getClient<C extends Client>(): C | undefined;
94 /** Returns the scope of the top stack. */
95 getScope(): Scope | undefined;
96 /** Returns the scope stack for domains or the process. */
97 getStack(): Layer[];
98 /** Returns the topmost scope layer in the order domain > local > process. */
99 getStackTop(): Layer;
100 /**
101 * @inheritDoc
102 */
103 captureException(exception: any, hint?: EventHint): string;
104 /**
105 * @inheritDoc
106 */
107 captureMessage(message: string, level?: Severity, hint?: EventHint): string;
108 /**
109 * @inheritDoc
110 */
111 captureEvent(event: Event, hint?: EventHint): string;
112 /**
113 * @inheritDoc
114 */
115 lastEventId(): string | undefined;
116 /**
117 * @inheritDoc
118 */
119 addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;
120 /**
121 * @inheritDoc
122 */
123 setUser(user: User | null): void;
124 /**
125 * @inheritDoc
126 */
127 setTags(tags: {
128 [key: string]: Primitive;
129 }): void;
130 /**
131 * @inheritDoc
132 */
133 setExtras(extras: Extras): void;
134 /**
135 * @inheritDoc
136 */
137 setTag(key: string, value: Primitive): void;
138 /**
139 * @inheritDoc
140 */
141 setExtra(key: string, extra: Extra): void;
142 /**
143 * @inheritDoc
144 */
145 setContext(name: string, context: {
146 [key: string]: any;
147 } | null): void;
148 /**
149 * @inheritDoc
150 */
151 configureScope(callback: (scope: Scope) => void): void;
152 /**
153 * @inheritDoc
154 */
155 run(callback: (hub: Hub) => void): void;
156 /**
157 * @inheritDoc
158 */
159 getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;
160 /**
161 * @inheritDoc
162 */
163 startSpan(context: SpanContext): Span;
164 /**
165 * @inheritDoc
166 */
167 startTransaction(context: TransactionContext, customSamplingContext?: CustomSamplingContext): Transaction;
168 /**
169 * @inheritDoc
170 */
171 traceHeaders(): {
172 [key: string]: string;
173 };
174 /**
175 * @inheritDoc
176 */
177 captureSession(endSession?: boolean): void;
178 /**
179 * @inheritDoc
180 */
181 endSession(): void;
182 /**
183 * @inheritDoc
184 */
185 startSession(context?: SessionContext): Session;
186 /**
187 * Sends the current Session on the scope
188 */
189 private _sendSessionUpdate;
190 /**
191 * Internal helper function to call a method on the top client if it exists.
192 *
193 * @param method The method to call on the client.
194 * @param args Arguments to pass to the client function.
195 */
196 private _invokeClient;
197 /**
198 * Calls global extension method and binding current instance to the function call
199 */
200 private _callExtensionMethod;
201}
202/**
203 * Returns the global shim registry.
204 *
205 * FIXME: This function is problematic, because despite always returning a valid Carrier,
206 * it has an optional `__SENTRY__` property, which then in turn requires us to always perform an unnecessary check
207 * at the call-site. We always access the carrier through this function, so we can guarantee that `__SENTRY__` is there.
208 **/
209export declare function getMainCarrier(): Carrier;
210/**
211 * Replaces the current main hub with the passed one on the global object
212 *
213 * @returns The old replaced hub
214 */
215export declare function makeMain(hub: Hub): Hub;
216/**
217 * Returns the default hub instance.
218 *
219 * If a hub is already registered in the global carrier but this module
220 * contains a more recent version, it replaces the registered version.
221 * Otherwise, the currently registered hub will be returned.
222 */
223export declare function getCurrentHub(): Hub;
224/**
225 * Returns the active domain, if one exists
226 * @deprecated No longer used; remove in v7
227 * @returns The domain, or undefined if there is no active domain
228 */
229export declare function getActiveDomain(): DomainAsCarrier | undefined;
230/**
231 * This will create a new {@link Hub} and add to the passed object on
232 * __SENTRY__.hub.
233 * @param carrier object
234 * @hidden
235 */
236export declare function getHubFromCarrier(carrier: Carrier): Hub;
237/**
238 * This will set passed {@link Hub} on the passed object's __SENTRY__.hub attribute
239 * @param carrier object
240 * @param hub Hub
241 * @returns A boolean indicating success or failure
242 */
243export declare function setHubOnCarrier(carrier: Carrier, hub: Hub): boolean;
244//# sourceMappingURL=hub.d.ts.map
\No newline at end of file