Skip to content

Commit 31c4886

Browse files
authored
fix: avoid leaking winston types (#932)
The winston instrumentation needs the winston types only internaly. Move them into an internal file to avoid leaking it to end user.
1 parent da792fe commit 31c4886

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

plugins/node/opentelemetry-instrumentation-winston/src/instrumentation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ import {
2929
isWrapped,
3030
safeExecuteInTheMiddle,
3131
} from '@opentelemetry/instrumentation';
32-
import {
33-
WinstonInstrumentationConfig,
32+
import type { WinstonInstrumentationConfig } from './types';
33+
import type {
3434
Winston2LogMethod,
3535
Winston2LoggerModule,
3636
Winston3LogMethod,
3737
Winston3Logger,
38-
} from './types';
38+
} from './internal-types';
3939
import { VERSION } from './version';
4040

4141
const winston3Versions = ['>=3 <4'];
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import type { Logger as Winston3Logger } from 'winston';
18+
import type {
19+
LoggerInstance as Winston2Logger,
20+
LogMethod as Winston2LogMethod,
21+
} from 'winston2';
22+
export type Winston3LogMethod = Winston3Logger['write'];
23+
export type { Winston3Logger };
24+
25+
export type { Winston2LogMethod };
26+
export type Winston2LoggerModule = {
27+
Logger: Winston2Logger & { prototype: { log: Winston2LogMethod } };
28+
};
29+
export type { Winston2Logger };

plugins/node/opentelemetry-instrumentation-winston/src/types.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,10 @@
1616

1717
import { Span } from '@opentelemetry/api';
1818
import { InstrumentationConfig } from '@opentelemetry/instrumentation';
19-
import type { Logger as Winston3Logger } from 'winston';
20-
import type {
21-
LoggerInstance as Winston2Logger,
22-
LogMethod as Winston2LogMethod,
23-
} from 'winston2';
2419

2520
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2621
export type LogHookFunction = (span: Span, record: Record<string, any>) => void;
2722

2823
export interface WinstonInstrumentationConfig extends InstrumentationConfig {
2924
logHook?: LogHookFunction;
3025
}
31-
32-
export type Winston3LogMethod = Winston3Logger['write'];
33-
export type { Winston3Logger };
34-
35-
export type { Winston2LogMethod };
36-
export type Winston2LoggerModule = {
37-
Logger: Winston2Logger & { prototype: { log: Winston2LogMethod } };
38-
};
39-
export type { Winston2Logger };

plugins/node/opentelemetry-instrumentation-winston/test/winston.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
2525
import * as assert from 'assert';
2626
import * as sinon from 'sinon';
2727
import { Writable } from 'stream';
28-
import type { Winston2Logger, Winston3Logger } from '../src/types';
28+
import type { Winston2Logger, Winston3Logger } from '../src/internal-types';
2929
import { WinstonInstrumentation } from '../src';
3030

3131
const memoryExporter = new InMemorySpanExporter();

0 commit comments

Comments
 (0)