UNPKG

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