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

Commit

Permalink
💬 Rename option sentryDsn --> sentry
Browse files Browse the repository at this point in the history
Now it can be a boolean, not just dsn.

Related: #28
  • Loading branch information
smolijar committed Nov 22, 2019
1 parent 886dc1b commit 4616b1e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ const defaultLogger = (options: AckeeLoggerOptions & { loggerName?: string } = {
serializers.disablePaths(options.disableFields);
serializers.enablePaths(options.enableFields);

if (options.sentryDsn) {
const sentry = require('@sentry/node')
if (typeof options.sentryDsn === 'string') {
sentry.init({ dsn: options.sentryDsn });
if (options.sentry) {
const sentry = require('@sentry/node');
if (typeof options.sentry === 'string') {
sentry.init({ dsn: options.sentry });
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export interface AckeeLoggerOptions {
ignoredHttpMethods?: string[];
config?: LoggerOptions;
pretty?: boolean;
sentryDsn?: string;
sentry?: string | boolean;
skip?: (req: Request, res?: Response) => boolean;
}
2 changes: 1 addition & 1 deletion src/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const initLoggerStreams = (

streams = decorateStreams(streams, getDefaultTransformStream(options));

if (options.sentryDsn) {
if (options.sentry) {
streams = decorateStreams(streams, SentryTransformStream);
}

Expand Down
8 changes: 4 additions & 4 deletions src/tests/sentry-mocked.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ describe('sentry mocked', () => {
});
test('can create logger with options', () => {
expect(() => loggerFactory()).not.toThrowError();
expect(() => loggerFactory({ sentryDsn: true })).not.toThrowError();
expect(() => loggerFactory({ sentry: true })).not.toThrowError();
expect(init).not.toHaveBeenCalled();
expect(() => loggerFactory({ sentryDsn: 'dummy' })).not.toThrowError();
expect(() => loggerFactory({ sentry: 'dummy' })).not.toThrowError();
expect(init.mock.calls[0]).toMatchInlineSnapshot(`
Array [
Object {
Expand All @@ -60,7 +60,7 @@ describe('sentry mocked', () => {
test('sentry captureMessage is called with correct scope', async () => {
await new Promise((resolve, reject) => {
const logger = loggerFactory({
sentryDsn: 'DSN',
sentry: 'DSN',
});
captureMessage.mockImplementation(createCapture(resolve));
logger.info('Foo');
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('sentry mocked', () => {
test('sentry captureException with stack and correct levels', async () => {
await new Promise((resolve, reject) => {
const logger = loggerFactory({
sentryDsn: 'DSN',
sentry: 'DSN',
});
captureException.mockReset();
captureException.mockImplementation(createCapture(resolve));
Expand Down
2 changes: 1 addition & 1 deletion src/tests/sentry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('sentry not available', () => {
});
test('without sentry lib works by default, but crashes on provided', () => {
expect(() => loggerFactory()).not.toThrowError();
expect(() => loggerFactory({ sentryDsn: 'DSN' })).toThrowErrorMatchingInlineSnapshot(
expect(() => loggerFactory({ sentry: 'DSN' })).toThrowErrorMatchingInlineSnapshot(
`"Cannot find module '@sentry/node' from 'index.ts'"`
);
});
Expand Down

0 comments on commit 4616b1e

Please sign in to comment.