Skip to content

Commit

Permalink
refactor: be more explicit with checking wrapped functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rauno56 committed Nov 26, 2021
1 parent dd84e69 commit f13d46a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ export type { Winston2LogMethod };
export type Winston2LoggerModule = {
Logger: Winston2Logger & { prototype: { log: Winston2LogMethod } };
};
export type { Winston2Logger };
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
import * as assert from 'assert';
import * as sinon from 'sinon';
import { Writable } from 'stream';
import type { Winston3Logger } from '../src/types';
import type { Winston2Logger, Winston3Logger } from '../src/types';
import { WinstonInstrumentation } from '../src';

const memoryExporter = new InMemorySpanExporter();
Expand All @@ -37,7 +37,7 @@ context.setGlobalContextManager(new AsyncHooksContextManager());
const kMessage = 'log-message';

describe('WinstonInstrumentation', () => {
let logger: Winston3Logger;
let logger: Winston3Logger | Winston2Logger;
let writeSpy: sinon.SinonSpy;
let instrumentation: WinstonInstrumentation;

Expand Down Expand Up @@ -100,8 +100,13 @@ describe('WinstonInstrumentation', () => {
beforeEach(initLogger);

it('wraps write', () => {
// winston 3.x || winston 2.x
assert.ok(isWrapped(logger['write']) || isWrapped(logger['log']));
if ('log' in logger) {
// winston 2.x
assert.ok(isWrapped(logger['log']));
} else {
// winston 3.x
assert.ok(isWrapped(logger['write']));
}
});

it('injects span context to records', () => {
Expand Down

0 comments on commit f13d46a

Please sign in to comment.