Skip to content

Commit

Permalink
Initialize sentry property
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Feb 12, 2024
1 parent 7783d91 commit 174b5ca
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function get(data: any, path: string) {
}

export class PinoSentryTransport {
public readonly sentry: typeof Sentry;
// Default minimum log level to `debug`
minimumLogLevel: ValueOf<typeof SeverityIota> = SeverityIota[Severity.Debug];
messageAttributeKey = 'msg';
Expand All @@ -87,17 +88,19 @@ export class PinoSentryTransport {
decorateScope = (_data: Record<string, unknown>, _scope: Sentry.Scope) => {/**/};

public constructor(options?: PinoSentryOptions) {
Sentry.init(this.validateOptions(options || {}));
const { sentry, ...initOptions} = this.validateOptions(options || {});
if (sentry) {
this.sentry = sentry;
} else {
Sentry.init(initOptions);
this.sentry = Sentry;
}
}

public getLogSeverity(level: keyof typeof SEVERITIES_MAP): Severity {
return SEVERITIES_MAP[level] || Severity.Info;
}

public get sentry() {
return Sentry;
}

public transformer(): stream.Transform {
return through.obj((chunk: any, _enc: any, cb: any) => {
this.prepareAndGo(chunk, cb);
Expand Down

0 comments on commit 174b5ca

Please sign in to comment.