UNPKG

4.71 kBTypeScriptView Raw
1import { Breadcrumb } from './breadcrumb';
2import { Context, Contexts } from './context';
3import { EventProcessor } from './eventprocessor';
4import { Extra, Extras } from './extra';
5import { Primitive } from './misc';
6import { RequestSession, Session } from './session';
7import { Severity } from './severity';
8import { Span } from './span';
9import { Transaction } from './transaction';
10import { User } from './user';
11/** JSDocs */
12export declare type CaptureContext = Scope | Partial<ScopeContext> | ((scope: Scope) => Scope);
13/** JSDocs */
14export interface ScopeContext {
15 user: User;
16 level: Severity;
17 extra: Extras;
18 contexts: Contexts;
19 tags: {
20 [key: string]: Primitive;
21 };
22 fingerprint: string[];
23 requestSession: RequestSession;
24}
25/**
26 * Holds additional event information. {@link Scope.applyToEvent} will be
27 * called by the client before an event will be 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 Severity}
77 */
78 setLevel(level: Severity): 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 * Clears all currently set Breadcrumbs.
136 */
137 clearBreadcrumbs(): this;
138}
139//# sourceMappingURL=scope.d.ts.map
\No newline at end of file