Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
✨ Add sentry option and tests
Browse files Browse the repository at this point in the history
Related: #28
  • Loading branch information
smolijar committed Nov 21, 2019
1 parent 5fe8416 commit 36f52c2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@sentry/node": "^5.9.0"
},
"devDependencies": {
"@sentry/node": "^5.9.0",
"@types/jest": "^24.0.13",
"@types/lodash.foreach": "^4.5.4",
"@types/lodash.isempty": "^4.4.4",
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ const defaultLogger = (options: AckeeLoggerOptions & { loggerName?: string } = {
(pinoms as any).multistream(streams)
) as PinoLogger) as AckeeLogger;

if (options.sentryDsn) {
const sentry = require('@sentry/node');
}

// Add maxLevel support to pino-multi-stream
// This could be replaced with custom pass-through stream being passed to multistream, which would filter the messages
const loggerStream = (logger as any)[(pino as any).symbols.streamSym] as any;
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ export interface AckeeLoggerOptions {
ignoredHttpMethods?: string[];
config?: LoggerOptions;
pretty?: boolean;
sentryDsn?: string;
skip?: (req: Request, res?: Response) => boolean;
}
8 changes: 8 additions & 0 deletions src/tests/sentry-mocked.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import loggerFactory from '..';

jest.mock('@sentry/node', () => {});

test('can create logger with options', () => {
expect(() => loggerFactory()).not.toThrowError();
expect(() => loggerFactory({ sentryDsn: 'DSN' })).not.toThrowError();
});
12 changes: 12 additions & 0 deletions src/tests/sentry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import loggerFactory from '..';

jest.mock('@sentry/node', () => {
throw new Error("Cannot find module '@sentry/node' from 'index.ts'");
});

test('without sentry lib works by default, but crashes on provided', () => {
expect(() => loggerFactory()).not.toThrowError();
expect(() => loggerFactory({ sentryDsn: 'DSN' })).toThrowErrorMatchingInlineSnapshot(
`"Cannot find module '@sentry/node' from 'index.ts'"`
);
});

0 comments on commit 36f52c2

Please sign in to comment.