diff --git a/plugins/node/opentelemetry-instrumentation-winston/src/types.ts b/plugins/node/opentelemetry-instrumentation-winston/src/types.ts index 60bd86c8f4..1901c2e928 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/src/types.ts +++ b/plugins/node/opentelemetry-instrumentation-winston/src/types.ts @@ -36,3 +36,4 @@ export type { Winston2LogMethod }; export type Winston2LoggerModule = { Logger: Winston2Logger & { prototype: { log: Winston2LogMethod } }; }; +export type { Winston2Logger }; diff --git a/plugins/node/opentelemetry-instrumentation-winston/test/winston.test.ts b/plugins/node/opentelemetry-instrumentation-winston/test/winston.test.ts index 67012dfaf2..c46204809e 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/test/winston.test.ts +++ b/plugins/node/opentelemetry-instrumentation-winston/test/winston.test.ts @@ -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(); @@ -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; @@ -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', () => {