1 | // Type definitions for Raven.js
|
2 | // Project: https://github.com/getsentry/raven-js
|
3 | // Definitions by: Santi Albo <https://github.com/santialbo/>, Benjamin Pannell <http://github.com/spartan563>
|
4 |
|
5 | declare var Raven: Raven.RavenStatic;
|
6 |
|
7 | export = Raven;
|
8 |
|
9 | declare namespace Raven {
|
10 | interface RavenOptions {
|
11 | /** The log level associated with this event. Default: error */
|
12 | level?: LogLevel;
|
13 |
|
14 | /** The name of the logger used by Sentry. Default: javascript */
|
15 | logger?: string;
|
16 |
|
17 | /** The environment of the application you are monitoring with Sentry */
|
18 | environment?: string;
|
19 |
|
20 | /** The release version of the application you are monitoring with Sentry */
|
21 | release?: string;
|
22 |
|
23 | /** The name of the server or device that the client is running on */
|
24 | serverName?: string;
|
25 |
|
26 | /** List of messages to be filtered out before being sent to Sentry. */
|
27 | ignoreErrors?: (RegExp | string)[];
|
28 |
|
29 | /** Similar to ignoreErrors, but will ignore errors from whole urls patching a regex pattern. */
|
30 | ignoreUrls?: (RegExp | string)[];
|
31 |
|
32 | /** The inverse of ignoreUrls. Only report errors from whole urls matching a regex pattern. */
|
33 | whitelistUrls?: (RegExp | string)[];
|
34 |
|
35 | /** An array of regex patterns to indicate which urls are a part of your app. */
|
36 | includePaths?: (RegExp | string)[];
|
37 |
|
38 | /** Additional data to be tagged onto the error. */
|
39 | tags?: {
|
40 | [id: string]: string;
|
41 | };
|
42 |
|
43 | /** set to true to get the stack trace of your message */
|
44 | stacktrace?: boolean;
|
45 |
|
46 | extra?: any;
|
47 |
|
48 | /** In some cases you may see issues where Sentry groups multiple events together when they should be separate entities. In other cases, Sentry simply doesn’t group events together because they’re so sporadic that they never look the same. */
|
49 | fingerprint?: string[];
|
50 |
|
51 | /** An array of strings representing keys that should be scrubbed from the payload sent to Sentry */
|
52 | sanitizeKeys?: (RegExp | string)[];
|
53 |
|
54 | /** A function which allows mutation of the data payload right before being sent to Sentry */
|
55 | dataCallback?: (data: any) => any;
|
56 |
|
57 | /** A callback function that allows you to apply your own filters to determine if the message should be sent to Sentry. */
|
58 | shouldSendCallback?: (data: any) => boolean;
|
59 |
|
60 | /** By default, Raven does not truncate messages. If you need to truncate characters for whatever reason, you may set this to limit the length. */
|
61 | maxMessageLength?: number;
|
62 |
|
63 | /** By default, Raven will truncate URLs as they appear in breadcrumbs and other meta interfaces to 250 characters in order to minimize bytes over the wire. This does *not* affect URLs in stack traces. */
|
64 | maxUrlLength?: number;
|
65 |
|
66 | /** By default, Raven captures all unhandled promise rejections using standard `unhandledrejection` event. If you want to disable this behaviour, set this option to `false` */
|
67 | captureUnhandledRejections?: boolean;
|
68 |
|
69 | /** Override the default HTTP data transport handler. */
|
70 | transport?: (options: RavenTransportOptions) => void;
|
71 |
|
72 | /** Append headers to the fetch or XMLHttpRequest request. Should be in a form of hash, were value can be string or function */
|
73 | headers?: {
|
74 | [key: string]: string | Function;
|
75 | };
|
76 |
|
77 | /** `fetch` init parameters */
|
78 | fetchParameters?: {
|
79 | [key: string]: string | Function;
|
80 | };
|
81 |
|
82 | /** Allow use of private/secretKey. */
|
83 | allowSecretKey?: boolean;
|
84 |
|
85 | /** Enables/disables instrumentation of globals. */
|
86 | instrument?: boolean | RavenInstrumentationOptions;
|
87 |
|
88 | /** Enables/disables automatic collection of breadcrumbs. */
|
89 | autoBreadcrumbs?: boolean | AutoBreadcrumbOptions;
|
90 |
|
91 | /** By default, Raven captures as many as 100 breadcrumb entries. If you find this too noisy, you can reduce this number by setting maxBreadcrumbs. Note that this number cannot be set higher than the default of 100. */
|
92 | maxBreadcrumbs?: number;
|
93 |
|
94 | /** A function that allows filtering or mutating breadcrumb payloads. Return false to throw away the breadcrumb. */
|
95 | breadcrumbCallback?: (data: any) => any;
|
96 |
|
97 | /**
|
98 | * A sampling rate to apply to events. A value of 0.0 will send no events, and a value of 1.0 will send all events (default).
|
99 | */
|
100 | sampleRate?: number;
|
101 |
|
102 | /**
|
103 | * By default, Raven.js attempts to suppress duplicate captured errors and messages that occur back-to-back.
|
104 | * Such events are often triggered by rogue code (e.g. from a `setInterval` callback in a browser extension),
|
105 | * are not actionable, and eat up your event quota.
|
106 | */
|
107 | allowDuplicates?: boolean;
|
108 |
|
109 | /**
|
110 | * If set to true, Raven.js outputs some light debugging information onto the console.
|
111 | */
|
112 | debug?: boolean;
|
113 | }
|
114 |
|
115 | interface RavenInstrumentationOptions {
|
116 | tryCatch?: boolean;
|
117 | }
|
118 |
|
119 | interface RavenStatic {
|
120 | /** Raven.js version. */
|
121 | VERSION: string;
|
122 |
|
123 | Plugins: {[id: string]: RavenPlugin};
|
124 |
|
125 | /**
|
126 | * Allow Raven to be configured as soon as it is loaded
|
127 | * It uses a global RavenConfig = {dsn: '...', config: {}}
|
128 | *
|
129 | * @return undefined
|
130 | */
|
131 | afterLoad(): void;
|
132 |
|
133 | /**
|
134 | * Allow multiple versions of Raven to be installed.
|
135 | * Strip Raven from the global context and returns the instance.
|
136 | *
|
137 | * @return {Raven}
|
138 | */
|
139 | noConflict(): RavenStatic;
|
140 |
|
141 | /**
|
142 | * Configure Raven with a DSN and extra options
|
143 | *
|
144 | * @param {string} dsn The public Sentry DSN
|
145 | * @param {object} options Optional set of global options [optional]
|
146 | * @return {Raven}
|
147 | */
|
148 | config(dsn: string, options?: RavenOptions): RavenStatic;
|
149 |
|
150 | /**
|
151 | * Installs a global window.onerror error handler
|
152 | * to capture and report uncaught exceptions.
|
153 | * At this point, install() is required to be called due
|
154 | * to the way TraceKit is set up.
|
155 | *
|
156 | * @return {Raven}
|
157 | */
|
158 | install(): RavenStatic;
|
159 |
|
160 | /**
|
161 | * Adds a plugin to Raven
|
162 | *
|
163 | * @return {Raven}
|
164 | */
|
165 | addPlugin(plugin: RavenPlugin, ...pluginArgs: any[]): RavenStatic;
|
166 |
|
167 | /**
|
168 | * Wrap code within a context so Raven can capture errors
|
169 | * reliably across domains that is executed immediately.
|
170 | *
|
171 | * @param {object} options A specific set of options for this context [optional]
|
172 | * @param {function} func The callback to be immediately executed within the context
|
173 | * @param {array} args An array of arguments to be called with the callback [optional]
|
174 | */
|
175 | context(func: Function, ...args: any[]): void;
|
176 | context(options: RavenOptions, func: Function, ...args: any[]): void;
|
177 |
|
178 | /**
|
179 | * Wrap code within a context and returns back a new function to be executed
|
180 | *
|
181 | * @param {object} options A specific set of options for this context [optional]
|
182 | * @param {function} func The function to be wrapped in a new context
|
183 | * @return {function} The newly wrapped functions with a context
|
184 | */
|
185 | wrap(func: Function): Function;
|
186 | wrap(options: RavenOptions, func: Function): Function;
|
187 | wrap<T extends Function>(func: T): T;
|
188 | wrap<T extends Function>(options: RavenOptions, func: T): T;
|
189 |
|
190 | /**
|
191 | * Uninstalls the global error handler.
|
192 | *
|
193 | * @return {Raven}
|
194 | */
|
195 | uninstall(): RavenStatic;
|
196 |
|
197 | /**
|
198 | * Manually capture an exception and send it over to Sentry
|
199 | *
|
200 | * @param {error|ErrorEvent|string} ex An exception to be logged
|
201 | * @param {object} options A specific set of options for this error [optional]
|
202 | * @return {Raven}
|
203 | */
|
204 | captureException(
|
205 | ex: unknown,
|
206 | options?: RavenOptions
|
207 | ): RavenStatic;
|
208 |
|
209 | /**
|
210 | * Manually send a message to Sentry
|
211 | *
|
212 | * @param {string} msg A plain message to be captured in Sentry
|
213 | * @param {object} options A specific set of options for this message [optional]
|
214 | * @return {Raven}
|
215 | */
|
216 | captureMessage(msg: string, options?: RavenOptions): RavenStatic;
|
217 |
|
218 | /** Log a breadcrumb */
|
219 | captureBreadcrumb(crumb: Breadcrumb): RavenStatic;
|
220 |
|
221 | /**
|
222 | * Set/Clear a user to be sent along with the payload.
|
223 | *
|
224 | * @param {object} user An object representing user data [optional]
|
225 | * If user is undefined, the current user context will be removed.
|
226 | * @return {Raven}
|
227 | */
|
228 | setUserContext(user?: {[key: string]: any}): RavenStatic;
|
229 |
|
230 | /**
|
231 | * Merge extra attributes to be sent along with the payload.
|
232 | *
|
233 | * @param {object} context A set of data to be merged with the current extra context data [optional]
|
234 | * If context is undefined, the current extra context data will be removed.
|
235 | * @return {Raven}
|
236 | */
|
237 | setExtraContext(context?: Object): RavenStatic;
|
238 |
|
239 | /**
|
240 | * Merge tags to be sent along with the payload.
|
241 | *
|
242 | * @param {object} tags A set of data to be merged with the current tag context data [optional]
|
243 | * If tags is undefined, the current tag context data will be removed.
|
244 | * @return {Raven}
|
245 | */
|
246 | setTagsContext(tags?: Object): RavenStatic;
|
247 |
|
248 | /** Clear all of the context. */
|
249 | clearContext(): RavenStatic;
|
250 |
|
251 | /** Get a copy of the current context. This cannot be mutated.*/
|
252 | getContext(): Object;
|
253 |
|
254 | /** Override the default HTTP data transport handler. */
|
255 | setTransport(
|
256 | transportFunction: (options: RavenTransportOptions) => void
|
257 | ): RavenStatic;
|
258 |
|
259 | /** Set environment of application */
|
260 | setEnvironment(environment: string): RavenStatic;
|
261 |
|
262 | /** Set release version of application */
|
263 | setRelease(release: string): RavenStatic;
|
264 |
|
265 | /** Get the latest raw exception that was captured by Raven.*/
|
266 | lastException(): Error;
|
267 |
|
268 | /** An event id is a globally unique id for the event that was just sent. This event id can be used to find the exact event from within Sentry. */
|
269 | lastEventId(): string;
|
270 |
|
271 | /** If you need to conditionally check if raven needs to be initialized or not, you can use the isSetup function. It will return true if Raven is already initialized. */
|
272 | isSetup(): boolean;
|
273 |
|
274 | /** Specify a function that allows mutation of the data payload right before being sent to Sentry. */
|
275 | setDataCallback(callback?: RavenCallback): RavenStatic;
|
276 |
|
277 | /** Specify a callback function that allows you to mutate or filter breadcrumbs when they are captured. */
|
278 | setBreadcrumbCallback(callback?: RavenCallback): RavenStatic;
|
279 |
|
280 | /** Specify a callback function that allows you to apply your own filters to determine if the message should be sent to Sentry. */
|
281 | setShouldSendCallback(callback?: RavenCallback): RavenStatic;
|
282 |
|
283 | /** Show Sentry user feedback dialog */
|
284 | showReportDialog(options?: Object): void;
|
285 |
|
286 | /**
|
287 | * Configure Raven DSN
|
288 | *
|
289 | * @param {string} dsn The public Sentry DSN
|
290 | */
|
291 | setDSN(dsn: string): void;
|
292 | }
|
293 |
|
294 | type RavenCallback = (data: any, orig?: (data: any) => any) => any | void;
|
295 |
|
296 | interface RavenTransportOptions {
|
297 | url: string;
|
298 | data: any;
|
299 | auth: {
|
300 | sentry_version: string;
|
301 | sentry_client: string;
|
302 | sentry_key: string;
|
303 | };
|
304 | onSuccess(): void;
|
305 | onError(error: Error & {request?: XMLHttpRequest}): void;
|
306 | }
|
307 |
|
308 | interface RavenPlugin {
|
309 | (raven: RavenStatic, ...args: any[]): RavenStatic;
|
310 | }
|
311 |
|
312 | interface Breadcrumb {
|
313 | message?: string;
|
314 | category?: string;
|
315 | level?: LogLevel;
|
316 | data?: any;
|
317 | type?: BreadcrumbType;
|
318 | }
|
319 |
|
320 | type BreadcrumbType = 'navigation' | 'http';
|
321 |
|
322 | interface AutoBreadcrumbOptions {
|
323 | xhr?: boolean;
|
324 | console?: boolean;
|
325 | dom?: boolean;
|
326 | location?: boolean;
|
327 | sentry?: boolean;
|
328 | }
|
329 |
|
330 | /** Event/Breadcrumb Severity. `critical` is for Breadcrumbs only and `fatal` is for Events only. */
|
331 | type LogLevel =
|
332 | | 'critical'
|
333 | | 'fatal'
|
334 | | 'error'
|
335 | | 'warning'
|
336 | | 'info'
|
337 | | 'debug'
|
338 | | 'warn'
|
339 | | 'log';
|
340 | }
|