UNPKG

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