UNPKG

5.49 kBTypeScriptView Raw
1import type { Attachment } from './attachment';
2import type { Breadcrumb } from './breadcrumb';
3import type { Context, Contexts } from './context';
4import type { EventProcessor } from './eventprocessor';
5import type { Extra, Extras } from './extra';
6import type { Primitive } from './misc';
7import type { RequestSession, Session } from './session';
8import type { Severity, SeverityLevel } from './severity';
9import type { Span } from './span';
10import type { Transaction } from './transaction';
11import type { User } from './user';
12/** JSDocs */
13export declare type CaptureContext = Scope | Partial<ScopeContext> | ((scope: Scope) => Scope);
14/** JSDocs */
15export interface ScopeContext {
16 user: User;
17 level: Severity | SeverityLevel;
18 extra: Extras;
19 contexts: Contexts;
20 tags: {
21 [key: string]: Primitive;
22 };
23 fingerprint: string[];
24 requestSession: RequestSession;
25}
26/**
27 * Holds additional event information. {@link Scope.applyToEvent} will be called by the client before an event is sent.
28 */
29export interface Scope {
30 /** Add new event processor that will be called after {@link applyToEvent}. */
31 addEventProcessor(callback: EventProcessor): this;
32 /**
33 * Updates user context information for future events.
34 *
35 * @param user User context object to be set in the current context. Pass `null` to unset the user.
36 */
37 setUser(user: User | null): this;
38 /**
39 * Returns the `User` if there is one
40 */
41 getUser(): User | undefined;
42 /**
43 * Set an object that will be merged sent as tags data with the event.
44 * @param tags Tags context object to merge into current context.
45 */
46 setTags(tags: {
47 [key: string]: Primitive;
48 }): this;
49 /**
50 * Set key:value that will be sent as tags data with the event.
51 *
52 * Can also be used to unset a tag by passing `undefined`.
53 *
54 * @param key String key of tag
55 * @param value Value of tag
56 */
57 setTag(key: string, value: Primitive): this;
58 /**
59 * Set an object that will be merged sent as extra data with the event.
60 * @param extras Extras object to merge into current context.
61 */
62 setExtras(extras: Extras): this;
63 /**
64 * Set key:value that will be sent as extra data with the event.
65 * @param key String of extra
66 * @param extra Any kind of data. This data will be normalized.
67 */
68 setExtra(key: string, extra: Extra): this;
69 /**
70 * Sets the fingerprint on the scope to send with the events.
71 * @param fingerprint string[] to group events in Sentry.
72 */
73 setFingerprint(fingerprint: string[]): this;
74 /**
75 * Sets the level on the scope for future events.
76 * @param level string {@link SeverityLevel}
77 */
78 setLevel(level: Severity | SeverityLevel): this;
79 /**
80 * Sets the transaction name on the scope for future events.
81 */
82 setTransactionName(name?: string): this;
83 /**
84 * Sets context data with the given name.
85 * @param name of the context
86 * @param context an object containing context data. This data will be normalized. Pass `null` to unset the context.
87 */
88 setContext(name: string, context: Context | null): this;
89 /**
90 * Sets the Span on the scope.
91 * @param span Span
92 */
93 setSpan(span?: Span): this;
94 /**
95 * Returns the `Span` if there is one
96 */
97 getSpan(): Span | undefined;
98 /**
99 * Returns the `Transaction` attached to the scope (if there is one)
100 */
101 getTransaction(): Transaction | undefined;
102 /**
103 * Returns the `Session` if there is one
104 */
105 getSession(): Session | undefined;
106 /**
107 * Sets the `Session` on the scope
108 */
109 setSession(session?: Session): this;
110 /**
111 * Returns the `RequestSession` if there is one
112 */
113 getRequestSession(): RequestSession | undefined;
114 /**
115 * Sets the `RequestSession` on the scope
116 */
117 setRequestSession(requestSession?: RequestSession): this;
118 /**
119 * Updates the scope with provided data. Can work in three variations:
120 * - plain object containing updatable attributes
121 * - Scope instance that'll extract the attributes from
122 * - callback function that'll receive the current scope as an argument and allow for modifications
123 * @param captureContext scope modifier to be used
124 */
125 update(captureContext?: CaptureContext): this;
126 /** Clears the current scope and resets its properties. */
127 clear(): this;
128 /**
129 * Sets the breadcrumbs in the scope
130 * @param breadcrumbs Breadcrumb
131 * @param maxBreadcrumbs number of max breadcrumbs to merged into event.
132 */
133 addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): this;
134 /**
135 * Get the last breadcrumb.
136 */
137 getLastBreadcrumb(): Breadcrumb | undefined;
138 /**
139 * Clears all currently set Breadcrumbs.
140 */
141 clearBreadcrumbs(): this;
142 /**
143 * Adds an attachment to the scope
144 * @param attachment Attachment options
145 */
146 addAttachment(attachment: Attachment): this;
147 /**
148 * Returns an array of attachments on the scope
149 */
150 getAttachments(): Attachment[];
151 /**
152 * Clears attachments from the scope
153 */
154 clearAttachments(): this;
155 /**
156 * Add data which will be accessible during event processing but won't get sent to Sentry
157 */
158 setSDKProcessingMetadata(newData: {
159 [key: string]: unknown;
160 }): this;
161}
162//# sourceMappingURL=scope.d.ts.map
\No newline at end of file