forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscope.ts
266 lines (228 loc) · 7.72 KB
/
scope.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import type { Attachment } from './attachment';
import type { Breadcrumb } from './breadcrumb';
import type { Client } from './client';
import type { Context, Contexts } from './context';
import type { Event, EventHint } from './event';
import type { EventProcessor } from './eventprocessor';
import type { Extra, Extras } from './extra';
import type { Primitive } from './misc';
import type { RequestSession, Session } from './session';
import type { SeverityLevel } from './severity';
import type { Span } from './span';
import type { PropagationContext } from './tracing';
import type { User } from './user';
/** JSDocs */
export type CaptureContext = Scope | Partial<ScopeContext> | ((scope: Scope) => Scope);
/** JSDocs */
export interface ScopeContext {
user: User;
level: SeverityLevel;
extra: Extras;
contexts: Contexts;
tags: { [key: string]: Primitive };
fingerprint: string[];
requestSession: RequestSession;
propagationContext: PropagationContext;
}
export interface ScopeData {
eventProcessors: EventProcessor[];
breadcrumbs: Breadcrumb[];
user: User;
tags: { [key: string]: Primitive };
extra: Extras;
contexts: Contexts;
attachments: Attachment[];
propagationContext: PropagationContext;
sdkProcessingMetadata: { [key: string]: unknown };
fingerprint: string[];
level?: SeverityLevel;
transactionName?: string;
span?: Span;
}
/**
* Holds additional event information.
*/
export interface Scope {
/**
* Update the client on the scope.
*/
setClient(client: Client | undefined): void;
/**
* Get the client assigned to this scope.
*
* It is generally recommended to use the global function `Sentry.getClient()` instead, unless you know what you are doing.
*/
getClient<C extends Client>(): C | undefined;
/**
* Sets the last event id on the scope.
* @param lastEventId The last event id of a captured event.
*/
setLastEventId(lastEventId: string | undefined): void;
/**
* This is the getter for lastEventId.
* @returns The last event id of a captured event.
*/
lastEventId(): string | undefined;
/**
* Add internal on change listener. Used for sub SDKs that need to store the scope.
* @hidden
*/
addScopeListener(callback: (scope: Scope) => void): void;
/** Add new event processor that will be called during event processing. */
addEventProcessor(callback: EventProcessor): this;
/** Get the data of this scope, which is applied to an event during processing. */
getScopeData(): ScopeData;
/**
* Updates user context information for future events.
*
* @param user User context object to be set in the current context. Pass `null` to unset the user.
*/
setUser(user: User | null): this;
/**
* Returns the `User` if there is one
*/
getUser(): User | undefined;
/**
* Set an object that will be merged sent as tags data with the event.
* @param tags Tags context object to merge into current context.
*/
setTags(tags: { [key: string]: Primitive }): this;
/**
* Set key:value that will be sent as tags data with the event.
*
* Can also be used to unset a tag by passing `undefined`.
*
* @param key String key of tag
* @param value Value of tag
*/
setTag(key: string, value: Primitive): this;
/**
* Set an object that will be merged sent as extra data with the event.
* @param extras Extras object to merge into current context.
*/
setExtras(extras: Extras): this;
/**
* Set key:value that will be sent as extra data with the event.
* @param key String of extra
* @param extra Any kind of data. This data will be normalized.
*/
setExtra(key: string, extra: Extra): this;
/**
* Sets the fingerprint on the scope to send with the events.
* @param fingerprint string[] to group events in Sentry.
*/
setFingerprint(fingerprint: string[]): this;
/**
* Sets the level on the scope for future events.
* @param level string {@link SeverityLevel}
*/
setLevel(level: SeverityLevel): this;
/**
* Sets the transaction name on the scope so that the name of the transaction
* (e.g. taken server route or page location) is attached to future events.
*
* IMPORTANT: Calling this function does NOT change the name of the currently active
* span. If you want to change the name of the active span, use `span.updateName()`
* instead.
*
* By default, the SDK updates the scope's transaction name automatically on sensible
* occasions, such as a page navigation or when handling a new request on the server.
*/
setTransactionName(name?: string): this;
/**
* Sets context data with the given name.
* @param name of the context
* @param context an object containing context data. This data will be normalized. Pass `null` to unset the context.
*/
setContext(name: string, context: Context | null): this;
/**
* Returns the `Session` if there is one
*/
getSession(): Session | undefined;
/**
* Sets the `Session` on the scope
*/
setSession(session?: Session): this;
/**
* Returns the `RequestSession` if there is one
*/
getRequestSession(): RequestSession | undefined;
/**
* Sets the `RequestSession` on the scope
*/
setRequestSession(requestSession?: RequestSession): this;
/**
* Updates the scope with provided data. Can work in three variations:
* - plain object containing updatable attributes
* - Scope instance that'll extract the attributes from
* - callback function that'll receive the current scope as an argument and allow for modifications
* @param captureContext scope modifier to be used
*/
update(captureContext?: CaptureContext): this;
/** Clears the current scope and resets its properties. */
clear(): this;
/**
* Adds a breadcrumb to the scope
* @param breadcrumb Breadcrumb
* @param maxBreadcrumbs number of max breadcrumbs to merged into event.
*/
addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): this;
/**
* Get the last breadcrumb.
*/
getLastBreadcrumb(): Breadcrumb | undefined;
/**
* Clears all breadcrumbs from the scope.
*/
clearBreadcrumbs(): this;
/**
* Adds an attachment to the scope
* @param attachment Attachment options
*/
addAttachment(attachment: Attachment): this;
/**
* Clears attachments from the scope
*/
clearAttachments(): this;
/**
* Add data which will be accessible during event processing but won't get sent to Sentry
*/
setSDKProcessingMetadata(newData: { [key: string]: unknown }): this;
/**
* Add propagation context to the scope, used for distributed tracing
*/
setPropagationContext(context: PropagationContext): this;
/**
* Get propagation context from the scope, used for distributed tracing
*/
getPropagationContext(): PropagationContext;
/**
* Capture an exception for this scope.
*
* @param exception The exception to capture.
* @param hint Optinal additional data to attach to the Sentry event.
* @returns the id of the captured Sentry event.
*/
captureException(exception: unknown, hint?: EventHint): string;
/**
* Capture a message for this scope.
*
* @param message The message to capture.
* @param level An optional severity level to report the message with.
* @param hint Optional additional data to attach to the Sentry event.
* @returns the id of the captured message.
*/
captureMessage(message: string, level?: SeverityLevel, hint?: EventHint): string;
/**
* Capture a Sentry event for this scope.
*
* @param event The event to capture.
* @param hint Optional additional data to attach to the Sentry event.
* @returns the id of the captured event.
*/
captureEvent(event: Event, hint?: EventHint): string;
/**
* Clone all data from this scope into a new scope.
*/
clone(): Scope;
}