@opentelemetry/instrumentation-winston 0.32.2 → 0.33.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.
@@ -28,29 +28,33 @@ class WinstonInstrumentation extends instrumentation_1.InstrumentationBase {
28
28
  init() {
29
29
  return [
30
30
  new instrumentation_1.InstrumentationNodeModuleDefinition('winston', winston3Versions, moduleExports => moduleExports, () => { }, [
31
- new instrumentation_1.InstrumentationNodeModuleFile('winston/lib/winston/logger.js', winston3Versions, logger => {
31
+ new instrumentation_1.InstrumentationNodeModuleFile('winston/lib/winston/logger.js', winston3Versions, (logger, moduleVersion) => {
32
+ this._diag.debug(`Applying patch for winston@${moduleVersion}`);
32
33
  if ((0, instrumentation_1.isWrapped)(logger.prototype['write'])) {
33
34
  this._unwrap(logger.prototype, 'write');
34
35
  }
35
36
  this._wrap(logger.prototype, 'write', this._getPatchedWrite());
36
37
  return logger;
37
- }, logger => {
38
+ }, (logger, moduleVersion) => {
38
39
  if (logger === undefined)
39
40
  return;
41
+ this._diag.debug(`Removing patch for winston@${moduleVersion}`);
40
42
  this._unwrap(logger.prototype, 'write');
41
43
  }),
42
44
  ]),
43
45
  new instrumentation_1.InstrumentationNodeModuleDefinition('winston', winstonPre3Versions, moduleExports => moduleExports, () => { }, [
44
- new instrumentation_1.InstrumentationNodeModuleFile('winston/lib/winston/logger.js', winstonPre3Versions, fileExports => {
46
+ new instrumentation_1.InstrumentationNodeModuleFile('winston/lib/winston/logger.js', winstonPre3Versions, (fileExports, moduleVersion) => {
47
+ this._diag.debug(`Applying patch for winston@${moduleVersion}`);
45
48
  const proto = fileExports.Logger.prototype;
46
49
  if ((0, instrumentation_1.isWrapped)(proto.log)) {
47
50
  this._unwrap(proto, 'log');
48
51
  }
49
52
  this._wrap(proto, 'log', this._getPatchedLog());
50
53
  return fileExports;
51
- }, fileExports => {
54
+ }, (fileExports, moduleVersion) => {
52
55
  if (fileExports === undefined)
53
56
  return;
57
+ this._diag.debug(`Removing patch for winston@${moduleVersion}`);
54
58
  this._unwrap(fileExports.Logger.prototype, 'log');
55
59
  }),
56
60
  ]),
@@ -69,7 +73,7 @@ class WinstonInstrumentation extends instrumentation_1.InstrumentationBase {
69
73
  }
70
74
  (0, instrumentation_1.safeExecuteInTheMiddle)(() => hook(span, record), err => {
71
75
  if (err) {
72
- api_1.diag.error('winston instrumentation: error calling logHook', err);
76
+ this._diag.error('error calling logHook', err);
73
77
  }
74
78
  }, true);
75
79
  }
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAO4B;AAC5B,oEAMwC;AAQxC,uCAAoC;AAEpC,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,wCAAwC,EAAE,iBAAO,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;IAES,IAAI;QACZ,OAAO;YACL,IAAI,qDAAmC,CACrC,SAAS,EACT,gBAAgB,EAChB,aAAa,CAAC,EAAE,CAAC,aAAa,EAC9B,GAAG,EAAE,GAAE,CAAC,EACR;gBACE,IAAI,+CAA6B,CAC/B,+BAA+B,EAC/B,gBAAgB,EAChB,MAAM,CAAC,EAAE;oBACP,IAAI,IAAA,2BAAS,EAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE;wBACxC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;qBACzC;oBAED,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;oBAC/D,OAAO,MAAM,CAAC;gBAChB,CA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AwB,EACxB,MAA+B;IAE/B,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE,WAAW,CAAC,OAAO;QAC7B,OAAO,EAAE,WAAW,CAAC,MAAM;QAC3B,WAAW,EAAE,IAAI,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE;KACvD,CAAC;IAEF,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,MAAM,CAAC;KACf;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,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\nimport {\n context,\n diag,\n trace,\n isSpanContextValid,\n Span,\n SpanContext,\n} from '@opentelemetry/api';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport type { WinstonInstrumentationConfig } from './types';\nimport type {\n Winston2LogMethod,\n Winston2LoggerModule,\n Winston3LogMethod,\n Winston3Logger,\n} from './internal-types';\nimport { VERSION } from './version';\n\nconst winston3Versions = ['>=3 <4'];\nconst winstonPre3Versions = ['>=1 <3'];\n\nexport class WinstonInstrumentation extends InstrumentationBase {\n constructor(config: WinstonInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-winston', VERSION, config);\n }\n\n protected init() {\n return [\n new InstrumentationNodeModuleDefinition<{}>(\n 'winston',\n winston3Versions,\n moduleExports => moduleExports,\n () => {},\n [\n new InstrumentationNodeModuleFile<Winston3Logger>(\n 'winston/lib/winston/logger.js',\n winston3Versions,\n logger => {\n if (isWrapped(logger.prototype['write'])) {\n this._unwrap(logger.prototype, 'write');\n }\n\n this._wrap(logger.prototype, 'write', this._getPatchedWrite());\n return logger;\n },\n logger => {\n if (logger === undefined) return;\n this._unwrap(logger.prototype, 'write');\n }\n ),\n ]\n ),\n new InstrumentationNodeModuleDefinition<{}>(\n 'winston',\n winstonPre3Versions,\n moduleExports => moduleExports,\n () => {},\n [\n new InstrumentationNodeModuleFile<Winston2LoggerModule>(\n 'winston/lib/winston/logger.js',\n winstonPre3Versions,\n fileExports => {\n const proto = fileExports.Logger.prototype;\n\n if (isWrapped(proto.log)) {\n this._unwrap(proto, 'log');\n }\n\n this._wrap(proto, 'log', this._getPatchedLog());\n\n return fileExports;\n },\n fileExports => {\n if (fileExports === undefined) return;\n this._unwrap(fileExports.Logger.prototype, 'log');\n }\n ),\n ]\n ),\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 diag.error('winston instrumentation: 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 span = trace.getSpan(context.active());\n\n if (!span) {\n return original.apply(this, args);\n }\n\n const spanContext = span.spanContext();\n\n if (!isSpanContextValid(spanContext)) {\n return original.apply(this, args);\n }\n\n const record = args[0];\n injectRecord(spanContext, record);\n instrumentation._callHook(span, record);\n\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: unknown,\n ...args: Parameters<typeof original>\n ) {\n const span = trace.getSpan(context.active());\n\n if (!span) {\n return original.apply(this, args);\n }\n\n const spanContext = span.spanContext();\n\n if (!isSpanContextValid(spanContext)) {\n return original.apply(this, args);\n }\n\n for (let i = args.length - 1; i >= 0; i--) {\n if (typeof args[i] === 'object') {\n const record = args[i];\n injectRecord(spanContext, record);\n instrumentation._callHook(span, record);\n return original.apply(this, args);\n }\n }\n\n const record = injectRecord(spanContext);\n\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 instrumentation._callHook(span, record);\n\n return original.apply(this, args);\n };\n };\n }\n}\n\nfunction injectRecord(\n spanContext: SpanContext,\n record?: Record<string, string>\n) {\n const fields = {\n trace_id: spanContext.traceId,\n span_id: spanContext.spanId,\n trace_flags: `0${spanContext.traceFlags.toString(16)}`,\n };\n\n if (!record) {\n return fields;\n }\n\n return Object.assign(record, fields);\n}\n"]}
1
+ {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAM4B;AAC5B,oEAMwC;AAQxC,uCAAoC;AAEpC,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,wCAAwC,EAAE,iBAAO,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;IAES,IAAI;QACZ,OAAO;YACL,IAAI,qDAAmC,CACrC,SAAS,EACT,gBAAgB,EAChB,aAAa,CAAC,EAAE,CAAC,aAAa,EAC9B,GAAG,EAAE,GAAE,CAAC,EACR;gBACE,IAAI,+CAA6B,CAC/B,+BAA+B,EAC/B,gBAAgB,EAChB,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE;oBACxB,IAAI,CAAC,KAAK,CAAC,KAAK,CAA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,CAAC,CAAC;wBACxC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;qBACnC;iBACF;gBAED,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;gBAEzC,MAAM,QAAQ,GACZ,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,UAAU;oBACzC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;oBACjB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;gBAElB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;gBACjC,eAAe,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBAExC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACpC,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;CACF;AAjKD,wDAiKC;AAED,SAAS,YAAY,CACnB,WAAwB,EACxB,MAA+B;IAE/B,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE,WAAW,CAAC,OAAO;QAC7B,OAAO,EAAE,WAAW,CAAC,MAAM;QAC3B,WAAW,EAAE,IAAI,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE;KACvD,CAAC;IAEF,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,MAAM,CAAC;KACf;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,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\nimport {\n context,\n trace,\n isSpanContextValid,\n Span,\n SpanContext,\n} from '@opentelemetry/api';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport type { WinstonInstrumentationConfig } from './types';\nimport type {\n Winston2LogMethod,\n Winston2LoggerModule,\n Winston3LogMethod,\n Winston3Logger,\n} from './internal-types';\nimport { VERSION } from './version';\n\nconst winston3Versions = ['>=3 <4'];\nconst winstonPre3Versions = ['>=1 <3'];\n\nexport class WinstonInstrumentation extends InstrumentationBase {\n constructor(config: WinstonInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-winston', VERSION, config);\n }\n\n protected init() {\n return [\n new InstrumentationNodeModuleDefinition<{}>(\n 'winston',\n winston3Versions,\n moduleExports => moduleExports,\n () => {},\n [\n new InstrumentationNodeModuleFile<Winston3Logger>(\n 'winston/lib/winston/logger.js',\n winston3Versions,\n (logger, moduleVersion) => {\n this._diag.debug(`Applying patch for winston@${moduleVersion}`);\n if (isWrapped(logger.prototype['write'])) {\n this._unwrap(logger.prototype, 'write');\n }\n\n this._wrap(logger.prototype, 'write', this._getPatchedWrite());\n return logger;\n },\n (logger, moduleVersion) => {\n if (logger === undefined) return;\n this._diag.debug(`Removing patch for winston@${moduleVersion}`);\n this._unwrap(logger.prototype, 'write');\n }\n ),\n ]\n ),\n new InstrumentationNodeModuleDefinition<{}>(\n 'winston',\n winstonPre3Versions,\n moduleExports => moduleExports,\n () => {},\n [\n new InstrumentationNodeModuleFile<Winston2LoggerModule>(\n 'winston/lib/winston/logger.js',\n winstonPre3Versions,\n (fileExports, moduleVersion) => {\n this._diag.debug(`Applying patch for winston@${moduleVersion}`);\n const proto = fileExports.Logger.prototype;\n\n if (isWrapped(proto.log)) {\n this._unwrap(proto, 'log');\n }\n\n this._wrap(proto, 'log', this._getPatchedLog());\n\n return fileExports;\n },\n (fileExports, moduleVersion) => {\n if (fileExports === undefined) return;\n this._diag.debug(`Removing patch for winston@${moduleVersion}`);\n this._unwrap(fileExports.Logger.prototype, 'log');\n }\n ),\n ]\n ),\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 span = trace.getSpan(context.active());\n\n if (!span) {\n return original.apply(this, args);\n }\n\n const spanContext = span.spanContext();\n\n if (!isSpanContextValid(spanContext)) {\n return original.apply(this, args);\n }\n\n const record = args[0];\n injectRecord(spanContext, record);\n instrumentation._callHook(span, record);\n\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: unknown,\n ...args: Parameters<typeof original>\n ) {\n const span = trace.getSpan(context.active());\n\n if (!span) {\n return original.apply(this, args);\n }\n\n const spanContext = span.spanContext();\n\n if (!isSpanContextValid(spanContext)) {\n return original.apply(this, args);\n }\n\n for (let i = args.length - 1; i >= 0; i--) {\n if (typeof args[i] === 'object') {\n const record = args[i];\n injectRecord(spanContext, record);\n instrumentation._callHook(span, record);\n return original.apply(this, args);\n }\n }\n\n const record = injectRecord(spanContext);\n\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 instrumentation._callHook(span, record);\n\n return original.apply(this, args);\n };\n };\n }\n}\n\nfunction injectRecord(\n spanContext: SpanContext,\n record?: Record<string, string>\n) {\n const fields = {\n trace_id: spanContext.traceId,\n span_id: spanContext.spanId,\n trace_flags: `0${spanContext.traceFlags.toString(16)}`,\n };\n\n if (!record) {\n return fields;\n }\n\n return Object.assign(record, fields);\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.32.2";
1
+ export declare const VERSION = "0.33.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -17,5 +17,5 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.VERSION = '0.32.2';
20
+ exports.VERSION = '0.33.0';
21
21
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,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 VERSION = '0.32.2';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,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 VERSION = '0.33.0';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-winston",
3
- "version": "0.32.2",
3
+ "version": "0.33.0",
4
4
  "description": "OpenTelemetry instrumentation for winston",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -35,10 +35,7 @@
35
35
  "files": [
36
36
  "build/src/**/*.js",
37
37
  "build/src/**/*.js.map",
38
- "build/src/**/*.d.ts",
39
- "doc",
40
- "LICENSE",
41
- "README.md"
38
+ "build/src/**/*.d.ts"
42
39
  ],
43
40
  "publishConfig": {
44
41
  "access": "public"
@@ -66,8 +63,8 @@
66
63
  "winston2": "npm:winston@2.4.7"
67
64
  },
68
65
  "dependencies": {
69
- "@opentelemetry/instrumentation": "^0.44.0"
66
+ "@opentelemetry/instrumentation": "^0.45.1"
70
67
  },
71
68
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-winston#readme",
72
- "gitHead": "a8c225d2febcac561a70ca586d3efd5a84f9f3fa"
69
+ "gitHead": "607d375595da3ab51b7f773ac360900121c4361b"
73
70
  }