@opentelemetry/instrumentation-winston 0.38.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -15,6 +15,12 @@ Compatible with OpenTelemetry JS API and SDK `1.0+`.
|
|
|
15
15
|
npm install --save @opentelemetry/instrumentation-winston
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
### Supported Versions
|
|
19
|
+
|
|
20
|
+
- [`winston`](https://www.npmjs.com/package/winston) versions `>=1.0.0 <4`
|
|
21
|
+
|
|
22
|
+
Log sending: [`winston`](https://www.npmjs.com/package/winston) versions `>=3.0.0 <4`
|
|
23
|
+
|
|
18
24
|
## Usage
|
|
19
25
|
|
|
20
26
|
```js
|
|
@@ -98,13 +104,42 @@ logHook: (span, record) => {
|
|
|
98
104
|
|
|
99
105
|
Log injection can be disabled with the `disableLogCorrelation: true` option.
|
|
100
106
|
|
|
101
|
-
###
|
|
107
|
+
### Using OpenTelemetryTransportV3 without instrumentation
|
|
108
|
+
|
|
109
|
+
[@opentelemetry/winston-transport](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/winston-transport) package exports the Winston transport class that is used to send records to the
|
|
110
|
+
OpenTelemetry Logs SDK. It can be used directly when configuring a Winston logger.
|
|
111
|
+
For example:
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
const logsAPI = require('@opentelemetry/api-logs');
|
|
115
|
+
const {
|
|
116
|
+
LoggerProvider,
|
|
117
|
+
SimpleLogRecordProcessor,
|
|
118
|
+
ConsoleLogRecordExporter,
|
|
119
|
+
} = require('@opentelemetry/sdk-logs');
|
|
120
|
+
const { OpenTelemetryTransportV3 } = require('@opentelemetry/winston-transport');
|
|
121
|
+
const winston = require('winston');
|
|
122
|
+
|
|
102
123
|
|
|
103
|
-
|
|
124
|
+
// To start a logger, you first need to initialize the Logger provider.
|
|
125
|
+
const loggerProvider = new LoggerProvider();
|
|
126
|
+
// Add a processor to export log record
|
|
127
|
+
loggerProvider.addLogRecordProcessor(
|
|
128
|
+
new SimpleLogRecordProcessor(new ConsoleLogRecordExporter())
|
|
129
|
+
);
|
|
130
|
+
logsAPI.logs.setGlobalLoggerProvider(loggerProvider);
|
|
104
131
|
|
|
105
|
-
|
|
132
|
+
const logger = winston.createLogger({
|
|
133
|
+
level: 'info',
|
|
134
|
+
transports: [
|
|
135
|
+
new winston.transports.Console(),
|
|
136
|
+
new OpenTelemetryTransportV3()
|
|
137
|
+
]
|
|
138
|
+
});
|
|
139
|
+
```
|
|
106
140
|
|
|
107
|
-
|
|
141
|
+
> [!IMPORTANT]
|
|
142
|
+
> Logs will be duplicated if `@opentelemetry/winston-transport` is added as a transport in `winston` and `@opentelemetry/instrumentation-winston` is configured with `disableLogSending: false`.
|
|
108
143
|
|
|
109
144
|
## Semantic Conventions
|
|
110
145
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
|
|
2
2
|
import type { WinstonInstrumentationConfig } from './types';
|
|
3
|
-
export declare class WinstonInstrumentation extends InstrumentationBase {
|
|
3
|
+
export declare class WinstonInstrumentation extends InstrumentationBase<WinstonInstrumentationConfig> {
|
|
4
4
|
constructor(config?: WinstonInstrumentationConfig);
|
|
5
5
|
protected init(): InstrumentationNodeModuleDefinition[];
|
|
6
|
-
getConfig(): WinstonInstrumentationConfig;
|
|
7
|
-
setConfig(config?: WinstonInstrumentationConfig): void;
|
|
8
6
|
private _callHook;
|
|
9
7
|
private _getPatchedWrite;
|
|
10
8
|
private _getPatchedLog;
|
|
@@ -65,18 +65,12 @@ class WinstonInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
65
65
|
winstons2instrumentationNodeModuleDefinition,
|
|
66
66
|
];
|
|
67
67
|
}
|
|
68
|
-
getConfig() {
|
|
69
|
-
return this._config;
|
|
70
|
-
}
|
|
71
|
-
setConfig(config = {}) {
|
|
72
|
-
this._config = config;
|
|
73
|
-
}
|
|
74
68
|
_callHook(span, record) {
|
|
75
|
-
const
|
|
76
|
-
if (!
|
|
69
|
+
const { logHook } = this.getConfig();
|
|
70
|
+
if (!logHook) {
|
|
77
71
|
return;
|
|
78
72
|
}
|
|
79
|
-
(0, instrumentation_1.safeExecuteInTheMiddle)(() =>
|
|
73
|
+
(0, instrumentation_1.safeExecuteInTheMiddle)(() => logHook(span, record), err => {
|
|
80
74
|
if (err) {
|
|
81
75
|
this._diag.error('error calling logHook', err);
|
|
82
76
|
}
|
|
@@ -144,7 +138,7 @@ class WinstonInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
144
138
|
args[0].transports = newTransports;
|
|
145
139
|
}
|
|
146
140
|
catch (err) {
|
|
147
|
-
instrumentation._diag.warn('
|
|
141
|
+
instrumentation._diag.warn('@opentelemetry/winston-transport is not available, log records will not be automatically sent.');
|
|
148
142
|
}
|
|
149
143
|
}
|
|
150
144
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA8E;AAC9E,sDAAyD;AACzD,oEAMwC;AASxC,uCAA0D;AAE1D,MAAM,gBAAgB,GAAG,CAAC,QAAQ,CAAC,CAAC;AACpC,MAAM,mBAAmB,GAAG,CAAC,QAAQ,CAAC,CAAC;AAEvC,MAAa,sBAAuB,SAAQ,qCAAmB;IAC7D,YAAY,SAAuC,EAAE;QACnD,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAES,IAAI;QACZ,MAAM,4CAA4C,GAChD,IAAI,qDAAmC,CACrC,SAAS,EACT,gBAAgB,EAChB,aAAa,CAAC,EAAE,CAAC,aAAa,EAC9B,GAAG,EAAE,GAAE,CAAC,EACR;YACE,IAAI,+CAA6B,CAC/B,+BAA+B,EAC/B,gBAAgB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gBACR,GAAG,CAAC,IAAI;gBACR,GAAG,CAAC,IAAI;gBACR,GAAG,CAAC,OAAO;gBACX,GAAG,CAAC,KAAK;gBACT,GAAG,CAAC,KAAK,CACV,CAAC;QACJ,CAAC;QAED,SAAS,cAAc,CAAC,GAAQ;YAC9B,OAAO,CACL,GAAG;gBACH,GAAG,CAAC,KAAK,KAAK,SAAS;gBACvB,GAAG,CAAC,KAAK;gBACT,GAAG,CAAC,IAAI;gBACR,GAAG,CAAC,KAAK;gBACT,GAAG,CAAC,OAAO;gBACX,GAAG,CAAC,MAAM;gBACV,GAAG,CAAC,IAAI;gBACR,GAAG,CAAC,KAAK,CACV,CAAC;QACJ,CAAC;QAED,OAAO;IACT,CAAC;CACF;AAzUD,wDAyUC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { context, trace, isSpanContextValid, Span } from '@opentelemetry/api';\nimport { SeverityNumber } from '@opentelemetry/api-logs';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport type { WinstonInstrumentationConfig } from './types';\nimport type {\n Winston2LoggerModule,\n Winston2LogMethod,\n Winston3ConfigureMethod,\n Winston3LogMethod,\n Winston3Logger,\n} from './internal-types';\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\nconst winston3Versions = ['>=3 <4'];\nconst winstonPre3Versions = ['>=1 <3'];\n\nexport class WinstonInstrumentation extends InstrumentationBase {\n constructor(config: WinstonInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n protected init() {\n const winstons3instrumentationNodeModuleDefinition =\n new InstrumentationNodeModuleDefinition(\n 'winston',\n winston3Versions,\n moduleExports => moduleExports,\n () => {},\n [\n new InstrumentationNodeModuleFile(\n 'winston/lib/winston/logger.js',\n winston3Versions,\n (logger: Winston3Logger) => {\n if (isWrapped(logger.prototype['write'])) {\n this._unwrap(logger.prototype, 'write');\n }\n this._wrap(logger.prototype, 'write', this._getPatchedWrite());\n\n // Wrap configure\n if (isWrapped(logger.prototype['configure'])) {\n this._unwrap(logger.prototype, 'configure');\n }\n this._wrap(\n logger.prototype,\n 'configure',\n this._getPatchedConfigure()\n );\n\n return logger;\n },\n (logger: Winston3Logger) => {\n if (logger === undefined) return;\n this._unwrap(logger.prototype, 'write');\n this._unwrap(logger.prototype, 'configure');\n }\n ),\n ]\n );\n\n const winstons2instrumentationNodeModuleDefinition =\n new InstrumentationNodeModuleDefinition(\n 'winston',\n winstonPre3Versions,\n moduleExports => moduleExports,\n () => {},\n [\n new InstrumentationNodeModuleFile(\n 'winston/lib/winston/logger.js',\n winstonPre3Versions,\n (fileExports: Winston2LoggerModule) => {\n const proto = fileExports.Logger.prototype;\n\n if (isWrapped(proto.log)) {\n this._unwrap(proto, 'log');\n }\n this._wrap(proto, 'log', this._getPatchedLog());\n\n return fileExports;\n },\n (fileExports: Winston2LoggerModule) => {\n if (fileExports === undefined) return;\n this._unwrap(fileExports.Logger.prototype, 'log');\n }\n ),\n ]\n );\n return [\n winstons3instrumentationNodeModuleDefinition,\n winstons2instrumentationNodeModuleDefinition,\n ];\n }\n\n override getConfig(): WinstonInstrumentationConfig {\n return this._config;\n }\n\n override setConfig(config: WinstonInstrumentationConfig = {}) {\n this._config = config;\n }\n\n private _callHook(span: Span, record: Record<string, string>) {\n const hook = this.getConfig().logHook;\n\n if (!hook) {\n return;\n }\n\n safeExecuteInTheMiddle(\n () => hook(span, record),\n err => {\n if (err) {\n this._diag.error('error calling logHook', err);\n }\n },\n true\n );\n }\n\n private _getPatchedWrite() {\n return (original: Winston3LogMethod) => {\n const instrumentation = this;\n return function patchedWrite(\n this: never,\n ...args: Parameters<typeof original>\n ) {\n const record = args[0];\n instrumentation._handleLogCorrelation(record);\n return original.apply(this, args);\n };\n };\n }\n\n private _getPatchedLog() {\n return (original: Winston2LogMethod) => {\n const instrumentation = this;\n return function patchedLog(\n this: never,\n ...args: Parameters<typeof original>\n ) {\n const record: Record<string, any> = {};\n instrumentation._handleLogCorrelation(record);\n // Inject in metadata argument\n let isDataInjected = false;\n for (let i = args.length - 1; i >= 0; i--) {\n if (typeof args[i] === 'object') {\n args[i] = Object.assign(args[i], record);\n isDataInjected = true;\n break;\n }\n }\n if (!isDataInjected) {\n const insertAt =\n typeof args[args.length - 1] === 'function'\n ? args.length - 1\n : args.length;\n\n args.splice(insertAt, 0, record);\n }\n\n return original.apply(this, args);\n };\n };\n }\n\n private _getPatchedConfigure() {\n return (original: Winston3ConfigureMethod) => {\n const instrumentation = this;\n return function patchedConfigure(\n this: never,\n ...args: Parameters<typeof original>\n ) {\n const config = instrumentation.getConfig();\n if (!config.disableLogSending) {\n if (args && args.length > 0) {\n // Try to load Winston transport\n try {\n const {\n OpenTelemetryTransportV3,\n } = require('@opentelemetry/winston-transport');\n const originalTransports = args[0].transports;\n let newTransports = Array.isArray(originalTransports)\n ? originalTransports\n : [];\n let transportOptions = {};\n if (config.logSeverity) {\n const winstonLevel = instrumentation._winstonLevelFromSeverity(\n config.logSeverity,\n args[0].levels\n );\n transportOptions = { level: winstonLevel };\n }\n const openTelemetryTransport = new OpenTelemetryTransportV3(\n transportOptions\n );\n if (originalTransports && !Array.isArray(originalTransports)) {\n newTransports = [originalTransports];\n }\n newTransports.push(openTelemetryTransport);\n args[0].transports = newTransports;\n } catch (err) {\n instrumentation._diag.warn(\n 'OpenTelemetry Winston transport is not available, log records will not be automatically sent.',\n err\n );\n }\n }\n }\n return original.apply(this, args);\n };\n };\n }\n\n private _handleLogCorrelation(record: Record<string, string>) {\n if (!this.getConfig().disableLogCorrelation) {\n const span = trace.getSpan(context.active());\n if (span) {\n const spanContext = span.spanContext();\n if (isSpanContextValid(spanContext)) {\n const fields = {\n trace_id: spanContext.traceId,\n span_id: spanContext.spanId,\n trace_flags: `0${spanContext.traceFlags.toString(16)}`,\n };\n const enhancedRecord = Object.assign(record, fields);\n this._callHook(span, enhancedRecord);\n return enhancedRecord;\n }\n }\n }\n return record;\n }\n\n private _winstonLevelFromSeverity(\n severity: SeverityNumber,\n winstonLevels: { [key: string]: number } | undefined\n ): string | undefined {\n if (winstonLevels) {\n if (isNpmLevels(winstonLevels)) {\n if (severity >= SeverityNumber.ERROR) {\n return 'error';\n } else if (severity >= SeverityNumber.WARN) {\n return 'warn';\n } else if (severity >= SeverityNumber.INFO) {\n return 'info';\n } else if (severity >= SeverityNumber.DEBUG3) {\n return 'http';\n } else if (severity >= SeverityNumber.DEBUG2) {\n return 'verbose';\n } else if (severity >= SeverityNumber.DEBUG) {\n return 'debug';\n } else if (severity >= SeverityNumber.TRACE) {\n return 'silly';\n }\n } else if (isCliLevels(winstonLevels)) {\n if (severity >= SeverityNumber.ERROR) {\n return 'error';\n } else if (severity >= SeverityNumber.WARN) {\n return 'warn';\n } else if (severity >= SeverityNumber.INFO3) {\n return 'help';\n } else if (severity >= SeverityNumber.INFO2) {\n return 'data';\n } else if (severity >= SeverityNumber.INFO) {\n return 'info';\n } else if (severity >= SeverityNumber.DEBUG) {\n return 'debug';\n } else if (severity >= SeverityNumber.TRACE4) {\n return 'prompt';\n } else if (severity >= SeverityNumber.TRACE3) {\n return 'verbose';\n } else if (severity >= SeverityNumber.TRACE2) {\n return 'input';\n } else if (severity >= SeverityNumber.TRACE) {\n return 'silly';\n }\n } else if (isSyslogLevels(winstonLevels)) {\n if (severity >= SeverityNumber.FATAL2) {\n return 'emerg';\n } else if (severity >= SeverityNumber.FATAL) {\n return 'alert';\n } else if (severity >= SeverityNumber.ERROR2) {\n return 'crit';\n } else if (severity >= SeverityNumber.ERROR) {\n return 'error';\n } else if (severity >= SeverityNumber.WARN) {\n return 'warning';\n } else if (severity >= SeverityNumber.INFO2) {\n return 'notice';\n } else if (severity >= SeverityNumber.INFO) {\n return 'info';\n } else if (severity >= SeverityNumber.TRACE) {\n return 'debug';\n }\n }\n // Unknown level\n this._diag.warn(\n 'failed to configure severity with existing winston levels'\n );\n }\n\n function isCliLevels(arg: any): boolean {\n return (\n arg &&\n arg.error !== undefined &&\n arg.warn &&\n arg.help &&\n arg.data &&\n arg.info &&\n arg.debug &&\n arg.prompt &&\n arg.verbose &&\n arg.input &&\n arg.silly\n );\n }\n\n function isNpmLevels(arg: any): boolean {\n return (\n arg &&\n arg.error !== undefined &&\n arg.warn &&\n arg.info &&\n arg.http &&\n arg.verbose &&\n arg.debug &&\n arg.silly\n );\n }\n\n function isSyslogLevels(arg: any): boolean {\n return (\n arg &&\n arg.emerg !== undefined &&\n arg.alert &&\n arg.crit &&\n arg.error &&\n arg.warning &&\n arg.notice &&\n arg.info &&\n arg.debug\n );\n }\n\n return;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA8E;AAC9E,sDAAyD;AACzD,oEAMwC;AASxC,uCAA0D;AAE1D,MAAM,gBAAgB,GAAG,CAAC,QAAQ,CAAC,CAAC;AACpC,MAAM,mBAAmB,GAAG,CAAC,QAAQ,CAAC,CAAC;AAEvC,MAAa,sBAAuB,SAAQ,qCAAiD;IAC3F,YAAY,SAAuC,EAAE;QACnD,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAES,IAAI;QACZ,MAAM,4CAA4C,GAChD,IAAI,qDAAmC,CACrC,SAAS,EACT,gBAAgB,EAChB,aAAa,CAAC,EAAE,CAAC,aAAa,EAC9B,GAAG,EAA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AK;gBACT,GAAG,CAAC,KAAK,CACV,CAAC;QACJ,CAAC;QAED,SAAS,cAAc,CAAC,GAAQ;YAC9B,OAAO,CACL,GAAG;gBACH,GAAG,CAAC,KAAK,KAAK,SAAS;gBACvB,GAAG,CAAC,KAAK;gBACT,GAAG,CAAC,IAAI;gBACR,GAAG,CAAC,KAAK;gBACT,GAAG,CAAC,OAAO;gBACX,GAAG,CAAC,MAAM;gBACV,GAAG,CAAC,IAAI;gBACR,GAAG,CAAC,KAAK,CACV,CAAC;QACJ,CAAC;QAED,OAAO;IACT,CAAC;CACF;AAhUD,wDAgUC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { context, trace, isSpanContextValid, Span } from '@opentelemetry/api';\nimport { SeverityNumber } from '@opentelemetry/api-logs';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport type { WinstonInstrumentationConfig } from './types';\nimport type {\n Winston2LoggerModule,\n Winston2LogMethod,\n Winston3ConfigureMethod,\n Winston3LogMethod,\n Winston3Logger,\n} from './internal-types';\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\nconst winston3Versions = ['>=3 <4'];\nconst winstonPre3Versions = ['>=1 <3'];\n\nexport class WinstonInstrumentation extends InstrumentationBase<WinstonInstrumentationConfig> {\n constructor(config: WinstonInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n protected init() {\n const winstons3instrumentationNodeModuleDefinition =\n new InstrumentationNodeModuleDefinition(\n 'winston',\n winston3Versions,\n moduleExports => moduleExports,\n () => {},\n [\n new InstrumentationNodeModuleFile(\n 'winston/lib/winston/logger.js',\n winston3Versions,\n (logger: Winston3Logger) => {\n if (isWrapped(logger.prototype['write'])) {\n this._unwrap(logger.prototype, 'write');\n }\n this._wrap(logger.prototype, 'write', this._getPatchedWrite());\n\n // Wrap configure\n if (isWrapped(logger.prototype['configure'])) {\n this._unwrap(logger.prototype, 'configure');\n }\n this._wrap(\n logger.prototype,\n 'configure',\n this._getPatchedConfigure()\n );\n\n return logger;\n },\n (logger: Winston3Logger) => {\n if (logger === undefined) return;\n this._unwrap(logger.prototype, 'write');\n this._unwrap(logger.prototype, 'configure');\n }\n ),\n ]\n );\n\n const winstons2instrumentationNodeModuleDefinition =\n new InstrumentationNodeModuleDefinition(\n 'winston',\n winstonPre3Versions,\n moduleExports => moduleExports,\n () => {},\n [\n new InstrumentationNodeModuleFile(\n 'winston/lib/winston/logger.js',\n winstonPre3Versions,\n (fileExports: Winston2LoggerModule) => {\n const proto = fileExports.Logger.prototype;\n\n if (isWrapped(proto.log)) {\n this._unwrap(proto, 'log');\n }\n this._wrap(proto, 'log', this._getPatchedLog());\n\n return fileExports;\n },\n (fileExports: Winston2LoggerModule) => {\n if (fileExports === undefined) return;\n this._unwrap(fileExports.Logger.prototype, 'log');\n }\n ),\n ]\n );\n return [\n winstons3instrumentationNodeModuleDefinition,\n winstons2instrumentationNodeModuleDefinition,\n ];\n }\n\n private _callHook(span: Span, record: Record<string, string>) {\n const { logHook } = this.getConfig();\n\n if (!logHook) {\n return;\n }\n\n safeExecuteInTheMiddle(\n () => logHook(span, record),\n err => {\n if (err) {\n this._diag.error('error calling logHook', err);\n }\n },\n true\n );\n }\n\n private _getPatchedWrite() {\n return (original: Winston3LogMethod) => {\n const instrumentation = this;\n return function patchedWrite(\n this: never,\n ...args: Parameters<typeof original>\n ) {\n const record = args[0];\n instrumentation._handleLogCorrelation(record);\n return original.apply(this, args);\n };\n };\n }\n\n private _getPatchedLog() {\n return (original: Winston2LogMethod) => {\n const instrumentation = this;\n return function patchedLog(\n this: never,\n ...args: Parameters<typeof original>\n ) {\n const record: Record<string, any> = {};\n instrumentation._handleLogCorrelation(record);\n // Inject in metadata argument\n let isDataInjected = false;\n for (let i = args.length - 1; i >= 0; i--) {\n if (typeof args[i] === 'object') {\n args[i] = Object.assign(args[i], record);\n isDataInjected = true;\n break;\n }\n }\n if (!isDataInjected) {\n const insertAt =\n typeof args[args.length - 1] === 'function'\n ? args.length - 1\n : args.length;\n\n args.splice(insertAt, 0, record);\n }\n\n return original.apply(this, args);\n };\n };\n }\n\n private _getPatchedConfigure() {\n return (original: Winston3ConfigureMethod) => {\n const instrumentation = this;\n return function patchedConfigure(\n this: never,\n ...args: Parameters<typeof original>\n ) {\n const config = instrumentation.getConfig();\n if (!config.disableLogSending) {\n if (args && args.length > 0) {\n // Try to load Winston transport\n try {\n const {\n OpenTelemetryTransportV3,\n } = require('@opentelemetry/winston-transport');\n const originalTransports = args[0].transports;\n let newTransports = Array.isArray(originalTransports)\n ? originalTransports\n : [];\n let transportOptions = {};\n if (config.logSeverity) {\n const winstonLevel = instrumentation._winstonLevelFromSeverity(\n config.logSeverity,\n args[0].levels\n );\n transportOptions = { level: winstonLevel };\n }\n const openTelemetryTransport = new OpenTelemetryTransportV3(\n transportOptions\n );\n if (originalTransports && !Array.isArray(originalTransports)) {\n newTransports = [originalTransports];\n }\n newTransports.push(openTelemetryTransport);\n args[0].transports = newTransports;\n } catch (err) {\n instrumentation._diag.warn(\n '@opentelemetry/winston-transport is not available, log records will not be automatically sent.'\n );\n }\n }\n }\n return original.apply(this, args);\n };\n };\n }\n\n private _handleLogCorrelation(record: Record<string, string>) {\n if (!this.getConfig().disableLogCorrelation) {\n const span = trace.getSpan(context.active());\n if (span) {\n const spanContext = span.spanContext();\n if (isSpanContextValid(spanContext)) {\n const fields = {\n trace_id: spanContext.traceId,\n span_id: spanContext.spanId,\n trace_flags: `0${spanContext.traceFlags.toString(16)}`,\n };\n const enhancedRecord = Object.assign(record, fields);\n this._callHook(span, enhancedRecord);\n return enhancedRecord;\n }\n }\n }\n return record;\n }\n\n private _winstonLevelFromSeverity(\n severity: SeverityNumber,\n winstonLevels: { [key: string]: number } | undefined\n ): string | undefined {\n if (winstonLevels) {\n if (isNpmLevels(winstonLevels)) {\n if (severity >= SeverityNumber.ERROR) {\n return 'error';\n } else if (severity >= SeverityNumber.WARN) {\n return 'warn';\n } else if (severity >= SeverityNumber.INFO) {\n return 'info';\n } else if (severity >= SeverityNumber.DEBUG3) {\n return 'http';\n } else if (severity >= SeverityNumber.DEBUG2) {\n return 'verbose';\n } else if (severity >= SeverityNumber.DEBUG) {\n return 'debug';\n } else if (severity >= SeverityNumber.TRACE) {\n return 'silly';\n }\n } else if (isCliLevels(winstonLevels)) {\n if (severity >= SeverityNumber.ERROR) {\n return 'error';\n } else if (severity >= SeverityNumber.WARN) {\n return 'warn';\n } else if (severity >= SeverityNumber.INFO3) {\n return 'help';\n } else if (severity >= SeverityNumber.INFO2) {\n return 'data';\n } else if (severity >= SeverityNumber.INFO) {\n return 'info';\n } else if (severity >= SeverityNumber.DEBUG) {\n return 'debug';\n } else if (severity >= SeverityNumber.TRACE4) {\n return 'prompt';\n } else if (severity >= SeverityNumber.TRACE3) {\n return 'verbose';\n } else if (severity >= SeverityNumber.TRACE2) {\n return 'input';\n } else if (severity >= SeverityNumber.TRACE) {\n return 'silly';\n }\n } else if (isSyslogLevels(winstonLevels)) {\n if (severity >= SeverityNumber.FATAL2) {\n return 'emerg';\n } else if (severity >= SeverityNumber.FATAL) {\n return 'alert';\n } else if (severity >= SeverityNumber.ERROR2) {\n return 'crit';\n } else if (severity >= SeverityNumber.ERROR) {\n return 'error';\n } else if (severity >= SeverityNumber.WARN) {\n return 'warning';\n } else if (severity >= SeverityNumber.INFO2) {\n return 'notice';\n } else if (severity >= SeverityNumber.INFO) {\n return 'info';\n } else if (severity >= SeverityNumber.TRACE) {\n return 'debug';\n }\n }\n // Unknown level\n this._diag.warn(\n 'failed to configure severity with existing winston levels'\n );\n }\n\n function isCliLevels(arg: any): boolean {\n return (\n arg &&\n arg.error !== undefined &&\n arg.warn &&\n arg.help &&\n arg.data &&\n arg.info &&\n arg.debug &&\n arg.prompt &&\n arg.verbose &&\n arg.input &&\n arg.silly\n );\n }\n\n function isNpmLevels(arg: any): boolean {\n return (\n arg &&\n arg.error !== undefined &&\n arg.warn &&\n arg.info &&\n arg.http &&\n arg.verbose &&\n arg.debug &&\n arg.silly\n );\n }\n\n function isSyslogLevels(arg: any): boolean {\n return (\n arg &&\n arg.emerg !== undefined &&\n arg.alert &&\n arg.crit &&\n arg.error &&\n arg.warning &&\n arg.notice &&\n arg.info &&\n arg.debug\n );\n }\n\n return;\n }\n}\n"]}
|
package/build/src/version.d.ts
CHANGED
package/build/src/version.js
CHANGED
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
|
|
19
19
|
// this is autogenerated file, see scripts/version-update.js
|
|
20
|
-
exports.PACKAGE_VERSION = '0.
|
|
20
|
+
exports.PACKAGE_VERSION = '0.40.0';
|
|
21
21
|
exports.PACKAGE_NAME = '@opentelemetry/instrumentation-winston';
|
|
22
22
|
//# sourceMappingURL=version.js.map
|
package/build/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,wCAAwC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,wCAAwC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.40.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-winston';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/instrumentation-winston",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"description": "OpenTelemetry instrumentation for `winston` logger",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"types": "build/src/index.d.ts",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"clean": "rimraf build/*",
|
|
13
13
|
"lint": "eslint . --ext .ts",
|
|
14
14
|
"lint:fix": "eslint . --ext .ts --fix",
|
|
15
|
+
"lint:readme": "node ../../../scripts/lint-readme.js",
|
|
15
16
|
"precompile": "tsc --version && lerna run version:update --scope @opentelemetry/instrumentation-winston --include-dependencies",
|
|
16
17
|
"prewatch": "npm run precompile",
|
|
17
18
|
"prepublishOnly": "npm run compile",
|
|
@@ -48,14 +49,14 @@
|
|
|
48
49
|
"@opentelemetry/context-async-hooks": "^1.21.0",
|
|
49
50
|
"@opentelemetry/sdk-trace-base": "^1.21.0",
|
|
50
51
|
"@opentelemetry/sdk-trace-node": "^1.21.0",
|
|
51
|
-
"@opentelemetry/winston-transport": "^0.
|
|
52
|
+
"@opentelemetry/winston-transport": "^0.6.0",
|
|
52
53
|
"@types/mocha": "7.0.2",
|
|
53
54
|
"@types/node": "18.6.5",
|
|
54
|
-
"@types/sinon": "10.0.
|
|
55
|
+
"@types/sinon": "10.0.20",
|
|
55
56
|
"@types/triple-beam": "^1.3.2",
|
|
56
57
|
"mocha": "7.2.0",
|
|
57
58
|
"nyc": "15.1.0",
|
|
58
|
-
"rimraf": "5.0.
|
|
59
|
+
"rimraf": "5.0.10",
|
|
59
60
|
"sinon": "15.2.0",
|
|
60
61
|
"test-all-versions": "6.1.0",
|
|
61
62
|
"ts-mocha": "10.0.0",
|
|
@@ -64,9 +65,9 @@
|
|
|
64
65
|
"winston2": "npm:winston@2.4.7"
|
|
65
66
|
},
|
|
66
67
|
"dependencies": {
|
|
67
|
-
"@opentelemetry/api-logs": "^0.
|
|
68
|
-
"@opentelemetry/instrumentation": "^0.
|
|
68
|
+
"@opentelemetry/api-logs": "^0.53.0",
|
|
69
|
+
"@opentelemetry/instrumentation": "^0.53.0"
|
|
69
70
|
},
|
|
70
71
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-winston#readme",
|
|
71
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "9dc58afed8134f95908331bcff35c5d9ec46fe9a"
|
|
72
73
|
}
|