UNPKG

8.18 kBTypeScriptView Raw
1import type { Attachment } from './attachment';
2import type { Breadcrumb } from './breadcrumb';
3import type { Client } from './client';
4import type { Context, Contexts } from './context';
5import type { Event, EventHint } from './event';
6import type { EventProcessor } from './eventprocessor';
7import type { Extra, Extras } from './extra';
8import type { Primitive } from './misc';
9import type { RequestSession, Session } from './session';
10import type { Severity, SeverityLevel } from './severity';
11import type { Span } from './span';
12import type { PropagationContext } from './tracing';
13import type { Transaction } from './transaction';
14import type { User } from './user';
15/** JSDocs */
16export type CaptureContext = Scope | Partial<ScopeContext> | ((scope: Scope) => Scope);
17/** JSDocs */
18export interface ScopeContext {
19 user: User;
20 level: Severity | SeverityLevel;
21 extra: Extras;
22 contexts: Contexts;
23 tags: {
24 [key: string]: Primitive;
25 };
26 fingerprint: string[];
27 requestSession: RequestSession;
28 propagationContext: PropagationContext;
29}
30export interface ScopeData {
31 eventProcessors: EventProcessor[];
32 breadcrumbs: Breadcrumb[];
33 user: User;
34 tags: {
35 [key: string]: Primitive;
36 };
37 extra: Extras;
38 contexts: Contexts;
39 attachments: Attachment[];
40 propagationContext: PropagationContext;
41 sdkProcessingMetadata: {
42 [key: string]: unknown;
43 };
44 fingerprint: string[];
45 level?: SeverityLevel;
46 /** @deprecated This will be removed in v8. */
47 transactionName?: string;
48 span?: Span;
49}
50/**
51 * Holds additional event information. {@link Scope.applyToEvent} will be called by the client before an event is sent.
52 */
53export interface Scope {
54 /**
55 * Update the client on the scope.
56 */
57 setClient(client: Client | undefined): void;
58 /**
59 * Get the client assigned to this scope.
60 *
61 * It is generally recommended to use the global function `Sentry.getClient()` instead, unless you know what you are doing.
62 */
63 getClient(): Client | undefined;
64 /** Add new event processor that will be called after {@link applyToEvent}. */
65 addEventProcessor(callback: EventProcessor): this;
66 /** Get the data of this scope, which is applied to an event during processing. */
67 getScopeData(): ScopeData;
68 /**
69 * Updates user context information for future events.
70 *
71 * @param user User context object to be set in the current context. Pass `null` to unset the user.
72 */
73 setUser(user: User | null): this;
74 /**
75 * Returns the `User` if there is one
76 */
77 getUser(): User | undefined;
78 /**
79 * Set an object that will be merged sent as tags data with the event.
80 * @param tags Tags context object to merge into current context.
81 */
82 setTags(tags: {
83 [key: string]: Primitive;
84 }): this;
85 /**
86 * Set key:value that will be sent as tags data with the event.
87 *
88 * Can also be used to unset a tag by passing `undefined`.
89 *
90 * @param key String key of tag
91 * @param value Value of tag
92 */
93 setTag(key: string, value: Primitive): this;
94 /**
95 * Set an object that will be merged sent as extra data with the event.
96 * @param extras Extras object to merge into current context.
97 */
98 setExtras(extras: Extras): this;
99 /**
100 * Set key:value that will be sent as extra data with the event.
101 * @param key String of extra
102 * @param extra Any kind of data. This data will be normalized.
103 */
104 setExtra(key: string, extra: Extra): this;
105 /**
106 * Sets the fingerprint on the scope to send with the events.
107 * @param fingerprint string[] to group events in Sentry.
108 */
109 setFingerprint(fingerprint: string[]): this;
110 /**
111 * Sets the level on the scope for future events.
112 * @param level string {@link SeverityLevel}
113 */
114 setLevel(level: Severity | SeverityLevel): this;
115 /**
116 * Sets the transaction name on the scope for future events.
117 */
118 setTransactionName(name?: string): this;
119 /**
120 * Sets context data with the given name.
121 * @param name of the context
122 * @param context an object containing context data. This data will be normalized. Pass `null` to unset the context.
123 */
124 setContext(name: string, context: Context | null): this;
125 /**
126 * Sets the Span on the scope.
127 * @param span Span
128 * @deprecated Instead of setting a span on a scope, use `startSpan()`/`startSpanManual()` instead.
129 */
130 setSpan(span?: Span): this;
131 /**
132 * Returns the `Span` if there is one.
133 * @deprecated Use `getActiveSpan()` instead.
134 */
135 getSpan(): Span | undefined;
136 /**
137 * Returns the `Transaction` attached to the scope (if there is one).
138 * @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead.
139 */
140 getTransaction(): Transaction | undefined;
141 /**
142 * Returns the `Session` if there is one
143 */
144 getSession(): Session | undefined;
145 /**
146 * Sets the `Session` on the scope
147 */
148 setSession(session?: Session): this;
149 /**
150 * Returns the `RequestSession` if there is one
151 */
152 getRequestSession(): RequestSession | undefined;
153 /**
154 * Sets the `RequestSession` on the scope
155 */
156 setRequestSession(requestSession?: RequestSession): this;
157 /**
158 * Updates the scope with provided data. Can work in three variations:
159 * - plain object containing updatable attributes
160 * - Scope instance that'll extract the attributes from
161 * - callback function that'll receive the current scope as an argument and allow for modifications
162 * @param captureContext scope modifier to be used
163 */
164 update(captureContext?: CaptureContext): this;
165 /** Clears the current scope and resets its properties. */
166 clear(): this;
167 /**
168 * Sets the breadcrumbs in the scope
169 * @param breadcrumbs Breadcrumb
170 * @param maxBreadcrumbs number of max breadcrumbs to merged into event.
171 */
172 addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): this;
173 /**
174 * Get the last breadcrumb.
175 */
176 getLastBreadcrumb(): Breadcrumb | undefined;
177 /**
178 * Clears all currently set Breadcrumbs.
179 */
180 clearBreadcrumbs(): this;
181 /**
182 * Adds an attachment to the scope
183 * @param attachment Attachment options
184 */
185 addAttachment(attachment: Attachment): this;
186 /**
187 * Returns an array of attachments on the scope
188 */
189 getAttachments(): Attachment[];
190 /**
191 * Clears attachments from the scope
192 */
193 clearAttachments(): this;
194 /**
195 * Add data which will be accessible during event processing but won't get sent to Sentry
196 */
197 setSDKProcessingMetadata(newData: {
198 [key: string]: unknown;
199 }): this;
200 /**
201 * Add propagation context to the scope, used for distributed tracing
202 */
203 setPropagationContext(context: PropagationContext): this;
204 /**
205 * Get propagation context from the scope, used for distributed tracing
206 */
207 getPropagationContext(): PropagationContext;
208 /**
209 * Capture an exception for this scope.
210 *
211 * @param exception The exception to capture.
212 * @param hint Optinal additional data to attach to the Sentry event.
213 * @returns the id of the captured Sentry event.
214 */
215 captureException(exception: unknown, hint?: EventHint): string;
216 /**
217 * Capture a message for this scope.
218 *
219 * @param exception The exception to capture.
220 * @param level An optional severity level to report the message with.
221 * @param hint Optional additional data to attach to the Sentry event.
222 * @returns the id of the captured message.
223 */
224 captureMessage(message: string, level?: SeverityLevel, hint?: EventHint): string;
225 /**
226 * Capture a Sentry event for this scope.
227 *
228 * @param exception The event to capture.
229 * @param hint Optional additional data to attach to the Sentry event.
230 * @returns the id of the captured event.
231 */
232 captureEvent(event: Event, hint?: EventHint): string;
233}
234//# sourceMappingURL=scope.d.ts.map
\No newline at end of file