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

Commit be9c3c9

Browse files
committed
✨ Add sentry option and tests
Related: #28
1 parent 8a30a4c commit be9c3c9

5 files changed

Lines changed: 26 additions & 0 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@sentry/node": "^5.9.0"
4949
},
5050
"devDependencies": {
51+
"@sentry/node": "^5.9.0",
5152
"@types/jest": "^24.0.13",
5253
"@types/lodash.foreach": "^4.5.4",
5354
"@types/lodash.isempty": "^4.4.4",

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ const defaultLogger = (options: AckeeLoggerOptions & { loggerName?: string } = {
9191
(pinoms as any).multistream(streams)
9292
) as PinoLogger) as AckeeLogger;
9393

94+
if (options.sentryDsn) {
95+
const sentry = require('@sentry/node');
96+
}
97+
9498
// Add maxLevel support to pino-multi-stream
9599
// This could be replaced with custom pass-through stream being passed to multistream, which would filter the messages
96100
const loggerStream = (logger as any)[(pino as any).symbols.streamSym] as any;

src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ export interface AckeeLoggerOptions {
2121
ignoredHttpMethods?: string[];
2222
config?: LoggerOptions;
2323
pretty?: boolean;
24+
sentryDsn?: string;
2425
skip?: (req: Request, res?: Response) => boolean;
2526
}

src/tests/sentry-mocked.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import loggerFactory from '..';
2+
3+
jest.mock('@sentry/node', () => {});
4+
5+
test('can create logger with options', () => {
6+
expect(() => loggerFactory()).not.toThrowError();
7+
expect(() => loggerFactory({ sentryDsn: 'DSN' })).not.toThrowError();
8+
});

src/tests/sentry.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import loggerFactory from '..';
2+
3+
jest.mock('@sentry/node', () => {
4+
throw new Error("Cannot find module '@sentry/node' from 'index.ts'");
5+
});
6+
7+
test('without sentry lib works by default, but crashes on provided', () => {
8+
expect(() => loggerFactory()).not.toThrowError();
9+
expect(() => loggerFactory({ sentryDsn: 'DSN' })).toThrowErrorMatchingInlineSnapshot(
10+
`"Cannot find module '@sentry/node' from 'index.ts'"`
11+
);
12+
});

0 commit comments

Comments
 (0)