Merge pull request #24045 from shreyjain1994/master

Update missing functions/deprecated functions for `raven`
This commit is contained in:
Armando Aguirre
2018-03-05 14:59:47 -08:00
committed by GitHub
2 changed files with 46 additions and 28 deletions
+45 -26
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/getsentry/raven-node
// Definitions by: Scott Cooper <https://github.com/scttcper>
// Dmitrii Sorin <https://github.com/1999>
// Shrey Jain <https://github.com/shreyjain1994>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
@@ -9,34 +10,50 @@
import { IncomingMessage, ServerResponse } from 'http';
import { EventEmitter } from 'events';
export const version: string;
// expose all methods of `Client` class since raven exposes a singleton instance
// todo: there has to be a better way of doing this that doesn't require duplicating so much stuff
export function config(options?: ConstructorOptions): Client;
export function config(dsn?: string | false, options?: ConstructorOptions): Client;
export function install(cb?: FatalErrorCallback): Client;
export function uninstall(): Client;
export function wrap<T>(func: () => T): () => T;
export function wrap<T>(options: any, func: () => T): () => T;
export function interceptErr(ctx: any): Client;
export function interceptErr(ctx: any): Client; // todo: part of public?
export function setContext(ctx: any): Client;
export function captureException(e: Error, cb?: CaptureCallback): string;
export function captureException(e: Error, options?: CaptureOptions, cb?: CaptureCallback): string;
export function captureMessage(message: string, cb?: CaptureCallback): string;
export function captureMessage(message: string, options?: CaptureOptions, cb?: CaptureCallback): string;
export function mergeContext(ctx: any): Client;
export function getContext(): any;
export function requestHandler(): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
export function errorHandler(): (e: Error, req: IncomingMessage, res: ServerResponse, next: () => void) => void;
export function captureException(e: Error, cb?: CaptureCallback): string;
export function captureException(e: Error, options?: CaptureOptions, cb?: CaptureCallback): string;
export function captureMessage(message: string, cb?: CaptureCallback): string;
export function captureMessage(message: string, options?: CaptureOptions, cb?: CaptureCallback): string;
export function captureBreadcrumb(breadcrumb: any): void;
export function setDataCallback(fn: DataCallback): Client;
export function setShouldSendCallback(fn: ShouldSendCallback): Client;
export function context<T>(ctx: any, func: () => T): T;
export function context<T>(func: () => T): T;
export function captureBreadcrumb(breadcrumb: any): void;
export const version: string;
export function disableConsoleAlerts(): void;
export function consoleAlert(msg: string): void;
export function parseDSN(dsn: string | false): parsedDSN;
export namespace utils {
function consoleAlert(msg: string): void;
function parseDSN(dsn: string | false): parsedDSN | false;
}
export class Client extends EventEmitter {
constructor(options: ConstructorOptions);
constructor(dsn: string, options?: ConstructorOptions);
config(dsn: string, options?: ConstructorOptions): this;
install(options?: ConstructorOptions, cb?: () => void): this;
constructor(options?: ConstructorOptions);
constructor(dsn?: string | false, options?: ConstructorOptions);
config(options?: ConstructorOptions): this;
config(dsn?: string | false, options?: ConstructorOptions): this;
install(cb?: FatalErrorCallback): this;
uninstall(): this;
wrap<T>(func: () => T): () => T;
wrap<T>(options: any, func: () => T): () => T;
setContext(ctx: any): this;
mergeContext(ctx: any): this;
getContext(): any;
requestHandler(): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
errorHandler(): (e: Error, req: IncomingMessage, res: ServerResponse, next: () => void) => void;
captureException(error: Error, cb?: CaptureCallback): string;
@@ -44,13 +61,12 @@ export class Client extends EventEmitter {
captureMessage(message: string, cb?: CaptureCallback): string;
captureMessage(message: string, options?: CaptureOptions, cb?: CaptureCallback): string;
captureBreadcrumb(breadcrumb: any): void;
setUserContext(data: UserData): void;
setDataCallback(fn: DataCallback): void;
setDataCallback(fn: DataCallback): this;
setShouldSendCallback(fn: ShouldSendCallback): this;
context<T>(ctx: any, func: () => T): T;
context<T>(func: () => T): T;
process(kwargs: any, cb?: () => void): void;
process(eventId: string, kwargs: any, cb?: () => void): void;
process(kwargs: any, cb?: () => void): void; // todo: part of public API?
process(eventId: string, kwargs: any, cb?: () => void): void; // todo: part of public API?
}
export interface ConstructorOptions {
@@ -65,19 +81,15 @@ export interface ConstructorOptions {
sampleRate?: number;
sendTimeout?: number;
shouldSendCallback?: ShouldSendCallback;
transport?(): void;
transport?: TransportCallback;
captureUnhandledRejections?: boolean;
autoBreadcrumbs?: boolean | any;
maxBreadcrumbs?: number;
autoBreadcrumbs?: boolean | { [breadcrumbType: string]: boolean };
parseUser?: boolean | string[] | parseUserCallback;
}
export type parseUserCallback = (req: any) => any;
export interface UserData {
id: string;
handle?: string;
}
export interface parsedDSN {
protocol: string;
public_key: string;
@@ -88,9 +100,16 @@ export interface parsedDSN {
port: number;
}
export type CaptureCallback = (err: { [key: string]: any }, eventId: any) => void;
export type FatalErrorCallback = (err: Error, sendErr: Error | null | undefined, eventId: string) => void;
export type DataCallback = (data: { [key: string]: any }) => void;
export type CaptureCallback = (sendErr: Error | null | undefined, eventId: any) => void;
/**
* Needs to return the modified data. It is not enough
* to just mutate the data and return nothing.
* https://github.com/getsentry/raven-node/blob/6f7145161a33134168ca87b53bb99b9b6d3c89e4/lib/client.js#L246-L248
*/
export type DataCallback = (data: { [key: string]: any }) => any;
export type ShouldSendCallback = (data: { [key: string]: any }) => boolean;
+1 -2
View File
@@ -13,7 +13,6 @@ console.log(Raven.version);
Raven.config({
release: 'foobar'
});
Raven.config(dsn).install({ captureUnhandledRejections: true });
client.setContext({});
client.on('logged', () => { });
client.process({});
@@ -34,4 +33,4 @@ Raven.context(() => {
Raven.captureBreadcrumb({});
});
setTimeout(Raven.wrap(() => {}), 1000);
Raven.parseDSN('https://8769c40cf49c4cc58b51fa45d8e2d166:296768aa91084e17b5ac02d3ad5bc7e7@app.getsentry.com/269');
Raven.utils.parseDSN('https://8769c40cf49c4cc58b51fa45d8e2d166:296768aa91084e17b5ac02d3ad5bc7e7@app.getsentry.com/269');