@opentelemetry/instrumentation-winston
Advanced tools
Comparing version 0.36.0 to 0.37.0
@@ -5,3 +5,3 @@ import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; | ||
constructor(config?: WinstonInstrumentationConfig); | ||
protected init(): InstrumentationNodeModuleDefinition<{}>[]; | ||
protected init(): InstrumentationNodeModuleDefinition[]; | ||
getConfig(): WinstonInstrumentationConfig; | ||
@@ -14,3 +14,4 @@ setConfig(config: WinstonInstrumentationConfig): void; | ||
private _handleLogCorrelation; | ||
private _winstonLevelFromSeverity; | ||
} | ||
//# sourceMappingURL=instrumentation.d.ts.map |
@@ -20,2 +20,3 @@ "use strict"; | ||
const api_1 = require("@opentelemetry/api"); | ||
const api_logs_1 = require("@opentelemetry/api-logs"); | ||
const instrumentation_1 = require("@opentelemetry/instrumentation"); | ||
@@ -31,4 +32,3 @@ const version_1 = require("./version"); | ||
const winstons3instrumentationNodeModuleDefinition = new instrumentation_1.InstrumentationNodeModuleDefinition('winston', winston3Versions, moduleExports => moduleExports, () => { }, [ | ||
new instrumentation_1.InstrumentationNodeModuleFile('winston/lib/winston/logger.js', winston3Versions, (logger, moduleVersion) => { | ||
this._diag.debug(`Applying patch for winston@${moduleVersion}`); | ||
new instrumentation_1.InstrumentationNodeModuleFile('winston/lib/winston/logger.js', winston3Versions, (logger) => { | ||
if ((0, instrumentation_1.isWrapped)(logger.prototype['write'])) { | ||
@@ -44,6 +44,5 @@ this._unwrap(logger.prototype, 'write'); | ||
return logger; | ||
}, (logger, moduleVersion) => { | ||
}, (logger) => { | ||
if (logger === undefined) | ||
return; | ||
this._diag.debug(`Removing patch for winston@${moduleVersion}`); | ||
this._unwrap(logger.prototype, 'write'); | ||
@@ -54,4 +53,3 @@ this._unwrap(logger.prototype, 'configure'); | ||
const winstons2instrumentationNodeModuleDefinition = new instrumentation_1.InstrumentationNodeModuleDefinition('winston', winstonPre3Versions, moduleExports => moduleExports, () => { }, [ | ||
new instrumentation_1.InstrumentationNodeModuleFile('winston/lib/winston/logger.js', winstonPre3Versions, (fileExports, moduleVersion) => { | ||
this._diag.debug(`Applying patch for winston@${moduleVersion}`); | ||
new instrumentation_1.InstrumentationNodeModuleFile('winston/lib/winston/logger.js', winstonPre3Versions, (fileExports) => { | ||
const proto = fileExports.Logger.prototype; | ||
@@ -63,6 +61,5 @@ if ((0, instrumentation_1.isWrapped)(proto.log)) { | ||
return fileExports; | ||
}, (fileExports, moduleVersion) => { | ||
}, (fileExports) => { | ||
if (fileExports === undefined) | ||
return; | ||
this._diag.debug(`Removing patch for winston@${moduleVersion}`); | ||
this._unwrap(fileExports.Logger.prototype, 'log'); | ||
@@ -142,3 +139,8 @@ }), | ||
: []; | ||
const openTelemetryTransport = new OpenTelemetryTransportV3(); | ||
let transportOptions = {}; | ||
if (config.logSeverity) { | ||
const winstonLevel = instrumentation._winstonLevelFromSeverity(config.logSeverity, args[0].levels); | ||
transportOptions = { level: winstonLevel }; | ||
} | ||
const openTelemetryTransport = new OpenTelemetryTransportV3(transportOptions); | ||
if (originalTransports && !Array.isArray(originalTransports)) { | ||
@@ -178,4 +180,126 @@ newTransports = [originalTransports]; | ||
} | ||
_winstonLevelFromSeverity(severity, winstonLevels) { | ||
if (winstonLevels) { | ||
if (isNpmLevels(winstonLevels)) { | ||
if (severity >= api_logs_1.SeverityNumber.ERROR) { | ||
return 'error'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.WARN) { | ||
return 'warn'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.INFO) { | ||
return 'info'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.DEBUG3) { | ||
return 'http'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.DEBUG2) { | ||
return 'verbose'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.DEBUG) { | ||
return 'debug'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.TRACE) { | ||
return 'silly'; | ||
} | ||
} | ||
else if (isCliLevels(winstonLevels)) { | ||
if (severity >= api_logs_1.SeverityNumber.ERROR) { | ||
return 'error'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.WARN) { | ||
return 'warn'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.INFO3) { | ||
return 'help'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.INFO2) { | ||
return 'data'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.INFO) { | ||
return 'info'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.DEBUG) { | ||
return 'debug'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.TRACE4) { | ||
return 'prompt'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.TRACE3) { | ||
return 'verbose'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.TRACE2) { | ||
return 'input'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.TRACE) { | ||
return 'silly'; | ||
} | ||
} | ||
else if (isSyslogLevels(winstonLevels)) { | ||
if (severity >= api_logs_1.SeverityNumber.FATAL2) { | ||
return 'emerg'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.FATAL) { | ||
return 'alert'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.ERROR2) { | ||
return 'crit'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.ERROR) { | ||
return 'error'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.WARN) { | ||
return 'warning'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.INFO2) { | ||
return 'notice'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.INFO) { | ||
return 'info'; | ||
} | ||
else if (severity >= api_logs_1.SeverityNumber.TRACE) { | ||
return 'debug'; | ||
} | ||
} | ||
// Unknown level | ||
this._diag.warn('failed to configure severity with existing winston levels'); | ||
} | ||
function isCliLevels(arg) { | ||
return (arg && | ||
arg.error !== undefined && | ||
arg.warn && | ||
arg.help && | ||
arg.data && | ||
arg.info && | ||
arg.debug && | ||
arg.prompt && | ||
arg.verbose && | ||
arg.input && | ||
arg.silly); | ||
} | ||
function isNpmLevels(arg) { | ||
return (arg && | ||
arg.error !== undefined && | ||
arg.warn && | ||
arg.info && | ||
arg.http && | ||
arg.verbose && | ||
arg.debug && | ||
arg.silly); | ||
} | ||
function isSyslogLevels(arg) { | ||
return (arg && | ||
arg.emerg !== undefined && | ||
arg.alert && | ||
arg.crit && | ||
arg.error && | ||
arg.warning && | ||
arg.notice && | ||
arg.info && | ||
arg.debug); | ||
} | ||
return; | ||
} | ||
} | ||
exports.WinstonInstrumentation = WinstonInstrumentation; | ||
//# sourceMappingURL=instrumentation.js.map |
import { Span } from '@opentelemetry/api'; | ||
import { SeverityNumber } from '@opentelemetry/api-logs'; | ||
import { InstrumentationConfig } from '@opentelemetry/instrumentation'; | ||
@@ -12,2 +13,6 @@ export declare type LogHookFunction = (span: Span, record: Record<string, any>) => void; | ||
/** | ||
* Control Log sending severity level, logs will be sent for specified severity and higher. | ||
*/ | ||
logSeverity?: SeverityNumber; | ||
/** | ||
* Whether to disable the injection trace-context fields, and possibly other | ||
@@ -14,0 +19,0 @@ * fields from `logHook()`, into log records for log correlation. |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.36.0"; | ||
export declare const VERSION = "0.37.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.36.0'; | ||
exports.VERSION = '0.37.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-winston", | ||
"version": "0.36.0", | ||
"version": "0.37.0", | ||
"description": "OpenTelemetry instrumentation for winston", | ||
@@ -51,3 +51,3 @@ "main": "build/src/index.js", | ||
"@opentelemetry/sdk-trace-node": "^1.21.0", | ||
"@opentelemetry/winston-transport": "^0.2.0", | ||
"@opentelemetry/winston-transport": "^0.3.0", | ||
"@types/mocha": "7.0.2", | ||
@@ -68,6 +68,7 @@ "@types/node": "18.6.5", | ||
"dependencies": { | ||
"@opentelemetry/instrumentation": "^0.50.0" | ||
"@opentelemetry/api-logs": "^0.51.0", | ||
"@opentelemetry/instrumentation": "^0.51.0" | ||
}, | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-winston#readme", | ||
"gitHead": "17a0bc1da3baa472ba9b867eee3c60730cc130fb" | ||
"gitHead": "96a87b48934f0afcf1fe637eed6704f35bd8e973" | ||
} |
@@ -63,2 +63,3 @@ # OpenTelemetry instrumentation for winston | ||
| `disableLogSending` | `boolean` | Whether to disable [log sending](#log-sending). Default `false`. | | ||
| `logSeverity` | `SeverityNumber` | Control severity level for [log sending](#log-sending). Default `SeverityNumber.UNSPECIFIED`, it will use Winston Logger's current level when unspecified. | | ||
| `disableLogCorrelation` | `boolean` | Whether to disable [log correlation](#log-correlation). Default `false`. | | ||
@@ -65,0 +66,0 @@ | `logHook` | `LogHookFunction` | An option hook to inject additional context to a log record after trace-context has been added. This requires `disableLogCorrelation` to be false. | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
63065
439
124
11
3
1
+ Added@opentelemetry/api-logs@0.51.1(transitive)
+ Added@opentelemetry/instrumentation@0.51.1(transitive)
+ Addedacorn-import-attributes@1.9.5(transitive)
+ Addedimport-in-the-middle@1.7.4(transitive)
- Removed@opentelemetry/api-logs@0.50.0(transitive)
- Removed@opentelemetry/instrumentation@0.50.0(transitive)
- Removedacorn-import-assertions@1.9.0(transitive)
- Removedimport-in-the-middle@1.7.1(transitive)