raygun
Version:
Raygun package for Node.js, written in TypeScript
145 lines (144 loc) • 5.85 kB
TypeScript
import { BreadcrumbMessage, Hook, Message, IOfflineStorage, OfflineStorageOptions, RaygunOptions, RequestParams, Tag, Transport, SendParameters, UserMessageData } from "./types";
import type { IncomingMessage } from "http";
import { Request, Response, NextFunction } from "express";
import { RaygunBatchTransport } from "./raygun.batch";
type SendCB = (error: Error | null, items: string[] | undefined) => void;
declare class Raygun {
_apiKey: string | undefined;
_filters: string[];
_user: UserMessageData | undefined;
_version: string;
_host: string | undefined;
_port: number | undefined;
_useSSL: boolean | undefined;
_timeout: number | undefined;
_onBeforeSend: Hook<Message | null> | undefined;
_offlineStorage: IOfflineStorage | undefined;
_isOffline: boolean | undefined;
_offlineStorageOptions: OfflineStorageOptions | undefined;
_groupingKey: Hook<string> | undefined;
_tags: Tag[] | undefined;
_useHumanStringForObject: boolean | undefined;
_reportColumnNumbers: boolean | undefined;
_innerErrorFieldName: string | undefined;
_batch: boolean;
_batchTransport: RaygunBatchTransport | undefined;
/**
* Initializes the Raygun Client.
* Use like:
* ```js
* const raygunClient = new Raygun.Client().init({
* apiKey: 'YOUR_API_KEY'
* });
* ```
* @param options - Raygun Client options
*/
init(options: RaygunOptions): this;
/**
* Override this method to provide user data from the send() method original request parameters.
* @param req - as RequestParams, may be null if send() was called without providing request parameters.
*/
user(req?: RequestParams): UserMessageData | null;
/**
* If you're using the `raygunClient.expressHandler`, you can send custom data along by setting this function.
*
* ```js
* raygunClient.expressCustomData = function (err, req) {
* return { 'level': err.level };
* };
* ```
*
* @param error - error captured
* @param request - original request object
*/
expressCustomData(error: Error, request: Request): {};
/**
* Set the version of the calling application
* @param version - Version as String
*/
setVersion(version: string): this;
/**
* Access or mutate the candidate error payload immediately before it is sent,
* or skip the sending action by returning null.
* @param onBeforeSend - callback that must return a Message object to send, or null to skip sending it.
*/
onBeforeSend(onBeforeSend: Hook<Message | null>): this;
/**
* Set the grouping key. Also, available as `init()` configuration parameter.
* @param groupingKey - grouping key method callback
*/
groupingKey(groupingKey: Hook<string>): this;
/**
* Notifies the Raygun Client that the machine is offline.
* Raygun Crash Reports will be stored and sent when the machine is back online.
*/
offline(): void;
/**
* Notifies the Raygun Client that the machine is online.
* Stored Raygun Crash Reports will be delivered.
* @param callback - sent result callback
*/
online(callback?: SendCB): void;
/**
* Set global tags to Raygun Client
* @param tags - list of Tags
*/
setTags(tags: Tag[]): void;
/**
* Adds breadcrumb to current context
* @param breadcrumb - either a string message or a Breadcrumb object
*/
addBreadcrumb(breadcrumb: string | BreadcrumbMessage): void;
/**
* Manually clear stored breadcrumbs for current context
*/
clearBreadcrumbs(): void;
transport(): Transport;
/**
* Sends exception to Raygun.
* @param exception - exception to send.
* @param customData - custom data to attach to the error report.
* @param request - custom RequestParams.
* @param tags - list of Tags to attach to the error report.
* @param timestamp - provides a custom timestamp as Date object or number in milliseconds since epoch.
* @param userInfo - provides the user information to this error report. Has priority over the user(request) method.
* @returns IncomingMessage if message was delivered, null if stored, rejected with Error if failed.
*/
send(exception: Error | string, { customData, request, tags, timestamp, userInfo }?: SendParameters): Promise<IncomingMessage | null>;
private reportUncaughtExceptions;
/**
* Send error using synchronous transport.
* Only used internally to report uncaught exceptions or unhandled promises.
* @param exception - error to report
* @param tags - optional tags
*/
private sendSync;
/**
* Attach as express middleware to create a breadcrumb store scope per request.
* e.g. `app.use(raygun.expressHandlerBreadcrumbs);`
* Then call to `raygun.addBreadcrumb(...)` to add breadcrumbs to the future Raygun `send` call.
* @param req - Express Request
* @param res - Express response
* @param next - Next Express function
*/
expressHandlerBreadcrumbs(req: Request, res: Response, next: NextFunction): void;
/**
* Attach as express middleware to report application errors to Raygun automatically.
* e.g. `app.use(raygun.expressHandler);`
* @param err - Captured Error by Express
* @param req - Express Request
* @param res - Express response
* @param next - Next Express function
*/
expressHandler(err: Error, req: Request, res: Response, next: NextFunction): void;
stop(): void;
private buildSendOptions;
private offlineTransport;
private offlineStorage;
}
export declare const Client: typeof Raygun;
export type Client = Raygun;
declare const _default: {
Client: typeof Raygun;
};
export default _default;