UNPKG

8.51 kBTypeScriptView Raw
1import { Breadcrumb, BreadcrumbHint } from './breadcrumb';
2import { Client } from './client';
3import { Event, EventHint } from './event';
4import { Extra, Extras } from './extra';
5import { Integration, IntegrationClass } from './integration';
6import { Primitive } from './misc';
7import { Scope } from './scope';
8import { Session, SessionContext } from './session';
9import { Severity } from './severity';
10import { Span, SpanContext } from './span';
11import { CustomSamplingContext, Transaction, TransactionContext } from './transaction';
12import { User } from './user';
13/**
14 * Internal class used to make sure we always have the latest internal functions
15 * working in case we have a version conflict.
16 */
17export interface Hub {
18 /**
19 * Checks if this hub's version is older than the given version.
20 *
21 * @param version A version number to compare to.
22 * @return True if the given version is newer; otherwise false.
23 *
24 * @hidden
25 */
26 isOlderThan(version: number): boolean;
27 /**
28 * This binds the given client to the current scope.
29 * @param client An SDK client (client) instance.
30 */
31 bindClient(client?: Client): void;
32 /**
33 * Create a new scope to store context information.
34 *
35 * The scope will be layered on top of the current one. It is isolated, i.e. all
36 * breadcrumbs and context information added to this scope will be removed once
37 * the scope ends. Be sure to always remove this scope with {@link this.popScope}
38 * when the operation finishes or throws.
39 *
40 * @returns Scope, the new cloned scope
41 */
42 pushScope(): Scope;
43 /**
44 * Removes a previously pushed scope from the stack.
45 *
46 * This restores the state before the scope was pushed. All breadcrumbs and
47 * context information added since the last call to {@link this.pushScope} are
48 * discarded.
49 */
50 popScope(): boolean;
51 /**
52 * Creates a new scope with and executes the given operation within.
53 * The scope is automatically removed once the operation
54 * finishes or throws.
55 *
56 * This is essentially a convenience function for:
57 *
58 * pushScope();
59 * callback();
60 * popScope();
61 *
62 * @param callback that will be enclosed into push/popScope.
63 */
64 withScope(callback: (scope: Scope) => void): void;
65 /** Returns the client of the top stack. */
66 getClient(): Client | undefined;
67 /**
68 * Captures an exception event and sends it to Sentry.
69 *
70 * @param exception An exception-like object.
71 * @param hint May contain additional information about the original exception.
72 * @returns The generated eventId.
73 */
74 captureException(exception: any, hint?: EventHint): string;
75 /**
76 * Captures a message event and sends it to Sentry.
77 *
78 * @param message The message to send to Sentry.
79 * @param level Define the level of the message.
80 * @param hint May contain additional information about the original exception.
81 * @returns The generated eventId.
82 */
83 captureMessage(message: string, level?: Severity, hint?: EventHint): string;
84 /**
85 * Captures a manually created event and sends it to Sentry.
86 *
87 * @param event The event to send to Sentry.
88 * @param hint May contain additional information about the original exception.
89 */
90 captureEvent(event: Event, hint?: EventHint): string;
91 /**
92 * This is the getter for lastEventId.
93 *
94 * @returns The last event id of a captured event.
95 */
96 lastEventId(): string | undefined;
97 /**
98 * Records a new breadcrumb which will be attached to future events.
99 *
100 * Breadcrumbs will be added to subsequent events to provide more context on
101 * user's actions prior to an error or crash.
102 *
103 * @param breadcrumb The breadcrumb to record.
104 * @param hint May contain additional information about the original breadcrumb.
105 */
106 addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;
107 /**
108 * Updates user context information for future events.
109 *
110 * @param user User context object to be set in the current context. Pass `null` to unset the user.
111 */
112 setUser(user: User | null): void;
113 /**
114 * Set an object that will be merged sent as tags data with the event.
115 *
116 * @param tags Tags context object to merge into current context.
117 */
118 setTags(tags: {
119 [key: string]: Primitive;
120 }): void;
121 /**
122 * Set key:value that will be sent as tags data with the event.
123 *
124 * Can also be used to unset a tag, by passing `undefined`.
125 *
126 * @param key String key of tag
127 * @param value Value of tag
128 */
129 setTag(key: string, value: Primitive): void;
130 /**
131 * Set key:value that will be sent as extra data with the event.
132 * @param key String of extra
133 * @param extra Any kind of data. This data will be normalized.
134 */
135 setExtra(key: string, extra: Extra): void;
136 /**
137 * Set an object that will be merged sent as extra data with the event.
138 * @param extras Extras object to merge into current context.
139 */
140 setExtras(extras: Extras): void;
141 /**
142 * Sets context data with the given name.
143 * @param name of the context
144 * @param context Any kind of data. This data will be normalized.
145 */
146 setContext(name: string, context: {
147 [key: string]: any;
148 } | null): void;
149 /**
150 * Callback to set context information onto the scope.
151 *
152 * @param callback Callback function that receives Scope.
153 */
154 configureScope(callback: (scope: Scope) => void): void;
155 /**
156 * For the duration of the callback, this hub will be set as the global current Hub.
157 * This function is useful if you want to run your own client and hook into an already initialized one
158 * e.g.: Reporting issues to your own sentry when running in your component while still using the users configuration.
159 */
160 run(callback: (hub: Hub) => void): void;
161 /** Returns the integration if installed on the current client. */
162 getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;
163 /** Returns all trace headers that are currently on the top scope. */
164 traceHeaders(): {
165 [key: string]: string;
166 };
167 /**
168 * @deprecated No longer does anything. Use use {@link Transaction.startChild} instead.
169 */
170 startSpan(context: SpanContext): Span;
171 /**
172 * Starts a new `Transaction` and returns it. This is the entry point to manual tracing instrumentation.
173 *
174 * A tree structure can be built by adding child spans to the transaction, and child spans to other spans. To start a
175 * new child span within the transaction or any span, call the respective `.startChild()` method.
176 *
177 * Every child span must be finished before the transaction is finished, otherwise the unfinished spans are discarded.
178 *
179 * The transaction must be finished with a call to its `.finish()` method, at which point the transaction with all its
180 * finished child spans will be sent to Sentry.
181 *
182 * @param context Properties of the new `Transaction`.
183 * @param customSamplingContext Information given to the transaction sampling function (along with context-dependent
184 * default values). See {@link Options.tracesSampler}.
185 *
186 * @returns The transaction which was just started
187 */
188 startTransaction(context: TransactionContext, customSamplingContext?: CustomSamplingContext): Transaction;
189 /**
190 * Starts a new `Session`, sets on the current scope and returns it.
191 *
192 * To finish a `session`, it has to be passed directly to `client.captureSession`, which is done automatically
193 * when using `hub.endSession()` for the session currently stored on the scope.
194 *
195 * When there's already an existing session on the scope, it'll be automatically ended.
196 *
197 * @param context Optional properties of the new `Session`.
198 *
199 * @returns The session which was just started
200 */
201 startSession(context?: SessionContext): Session;
202 /**
203 * Ends the session that lives on the current scope and sends it to Sentry
204 */
205 endSession(): void;
206 /**
207 * Sends the current session on the scope to Sentry
208 * @param endSession If set the session will be marked as exited and removed from the scope
209 */
210 captureSession(endSession: boolean): void;
211}
212//# sourceMappingURL=hub.d.ts.map
\No newline at end of file