@opentelemetry/instrumentation-ioredis
Advanced tools
Comparing version 0.35.2 to 0.35.3
@@ -11,5 +11,5 @@ import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; | ||
private _patchConnection; | ||
private traceSendCommand; | ||
private traceConnection; | ||
private _traceSendCommand; | ||
private _traceConnection; | ||
} | ||
//# sourceMappingURL=instrumentation.d.ts.map |
@@ -32,100 +32,9 @@ "use strict"; | ||
super('@opentelemetry/instrumentation-ioredis', version_1.VERSION, Object.assign({}, DEFAULT_CONFIG, _config)); | ||
this.traceSendCommand = (original, moduleVersion) => { | ||
const instrumentation = this; | ||
return function (cmd) { | ||
if (arguments.length < 1 || typeof cmd !== 'object') { | ||
return original.apply(this, arguments); | ||
} | ||
const config = instrumentation.getConfig(); | ||
const dbStatementSerializer = (config === null || config === void 0 ? void 0 : config.dbStatementSerializer) || redis_common_1.defaultDbStatementSerializer; | ||
const hasNoParentSpan = api_1.trace.getSpan(api_1.context.active()) === undefined; | ||
if ((config === null || config === void 0 ? void 0 : config.requireParentSpan) === true && hasNoParentSpan) { | ||
return original.apply(this, arguments); | ||
} | ||
const span = instrumentation.tracer.startSpan(cmd.name, { | ||
kind: api_1.SpanKind.CLIENT, | ||
attributes: { | ||
[semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: semantic_conventions_1.DbSystemValues.REDIS, | ||
[semantic_conventions_1.SemanticAttributes.DB_STATEMENT]: dbStatementSerializer(cmd.name, cmd.args), | ||
}, | ||
}); | ||
if (config === null || config === void 0 ? void 0 : config.requestHook) { | ||
(0, instrumentation_2.safeExecuteInTheMiddle)(() => config === null || config === void 0 ? void 0 : config.requestHook(span, { | ||
moduleVersion, | ||
cmdName: cmd.name, | ||
cmdArgs: cmd.args, | ||
}), e => { | ||
if (e) { | ||
api_1.diag.error('ioredis instrumentation: request hook failed', e); | ||
} | ||
}, true); | ||
} | ||
const { host, port } = this.options; | ||
span.setAttributes({ | ||
[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: host, | ||
[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: port, | ||
[semantic_conventions_1.SemanticAttributes.DB_CONNECTION_STRING]: `redis://${host}:${port}`, | ||
}); | ||
try { | ||
const result = original.apply(this, arguments); | ||
const origResolve = cmd.resolve; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
cmd.resolve = function (result) { | ||
(0, instrumentation_2.safeExecuteInTheMiddle)(() => { var _a; return (_a = config === null || config === void 0 ? void 0 : config.responseHook) === null || _a === void 0 ? void 0 : _a.call(config, span, cmd.name, cmd.args, result); }, e => { | ||
if (e) { | ||
api_1.diag.error('ioredis instrumentation: response hook failed', e); | ||
} | ||
}, true); | ||
(0, utils_1.endSpan)(span, null); | ||
origResolve(result); | ||
}; | ||
const origReject = cmd.reject; | ||
cmd.reject = function (err) { | ||
(0, utils_1.endSpan)(span, err); | ||
origReject(err); | ||
}; | ||
return result; | ||
} | ||
catch (error) { | ||
(0, utils_1.endSpan)(span, error); | ||
throw error; | ||
} | ||
}; | ||
}; | ||
this.traceConnection = (original) => { | ||
const instrumentation = this; | ||
return function () { | ||
const config = instrumentation.getConfig(); | ||
const hasNoParentSpan = api_1.trace.getSpan(api_1.context.active()) === undefined; | ||
if ((config === null || config === void 0 ? void 0 : config.requireParentSpan) === true && hasNoParentSpan) { | ||
return original.apply(this, arguments); | ||
} | ||
const span = instrumentation.tracer.startSpan('connect', { | ||
kind: api_1.SpanKind.CLIENT, | ||
attributes: { | ||
[semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: semantic_conventions_1.DbSystemValues.REDIS, | ||
[semantic_conventions_1.SemanticAttributes.DB_STATEMENT]: 'connect', | ||
}, | ||
}); | ||
const { host, port } = this.options; | ||
span.setAttributes({ | ||
[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: host, | ||
[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: port, | ||
[semantic_conventions_1.SemanticAttributes.DB_CONNECTION_STRING]: `redis://${host}:${port}`, | ||
}); | ||
try { | ||
const client = original.apply(this, arguments); | ||
(0, utils_1.endSpan)(span, null); | ||
return client; | ||
} | ||
catch (error) { | ||
(0, utils_1.endSpan)(span, error); | ||
throw error; | ||
} | ||
}; | ||
}; | ||
} | ||
init() { | ||
return [ | ||
new instrumentation_1.InstrumentationNodeModuleDefinition('ioredis', ['>1', '<6'], (moduleExports, moduleVersion) => { | ||
new instrumentation_1.InstrumentationNodeModuleDefinition('ioredis', ['>1', '<6'], (module, moduleVersion) => { | ||
const moduleExports = module[Symbol.toStringTag] === 'Module' | ||
? module.default // ESM | ||
: module; // CommonJS | ||
api_1.diag.debug('Applying patch for ioredis'); | ||
@@ -140,6 +49,9 @@ if ((0, instrumentation_1.isWrapped)(moduleExports.prototype.sendCommand)) { | ||
this._wrap(moduleExports.prototype, 'connect', this._patchConnection()); | ||
return moduleExports; | ||
}, moduleExports => { | ||
if (moduleExports === undefined) | ||
return module; | ||
}, module => { | ||
if (module === undefined) | ||
return; | ||
const moduleExports = module[Symbol.toStringTag] === 'Module' | ||
? module.default // ESM | ||
: module; // CommonJS | ||
api_1.diag.debug('Removing patch for ioredis'); | ||
@@ -156,3 +68,3 @@ this._unwrap(moduleExports.prototype, 'sendCommand'); | ||
return (original) => { | ||
return this.traceSendCommand(original, moduleVersion); | ||
return this._traceSendCommand(original, moduleVersion); | ||
}; | ||
@@ -162,7 +74,101 @@ } | ||
return (original) => { | ||
return this.traceConnection(original); | ||
return this._traceConnection(original); | ||
}; | ||
} | ||
_traceSendCommand(original, moduleVersion) { | ||
const instrumentation = this; | ||
return function (cmd) { | ||
if (arguments.length < 1 || typeof cmd !== 'object') { | ||
return original.apply(this, arguments); | ||
} | ||
const config = instrumentation.getConfig(); | ||
const dbStatementSerializer = (config === null || config === void 0 ? void 0 : config.dbStatementSerializer) || redis_common_1.defaultDbStatementSerializer; | ||
const hasNoParentSpan = api_1.trace.getSpan(api_1.context.active()) === undefined; | ||
if ((config === null || config === void 0 ? void 0 : config.requireParentSpan) === true && hasNoParentSpan) { | ||
return original.apply(this, arguments); | ||
} | ||
const span = instrumentation.tracer.startSpan(cmd.name, { | ||
kind: api_1.SpanKind.CLIENT, | ||
attributes: { | ||
[semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: semantic_conventions_1.DbSystemValues.REDIS, | ||
[semantic_conventions_1.SemanticAttributes.DB_STATEMENT]: dbStatementSerializer(cmd.name, cmd.args), | ||
}, | ||
}); | ||
if (config === null || config === void 0 ? void 0 : config.requestHook) { | ||
(0, instrumentation_2.safeExecuteInTheMiddle)(() => config === null || config === void 0 ? void 0 : config.requestHook(span, { | ||
moduleVersion, | ||
cmdName: cmd.name, | ||
cmdArgs: cmd.args, | ||
}), e => { | ||
if (e) { | ||
api_1.diag.error('ioredis instrumentation: request hook failed', e); | ||
} | ||
}, true); | ||
} | ||
const { host, port } = this.options; | ||
span.setAttributes({ | ||
[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: host, | ||
[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: port, | ||
[semantic_conventions_1.SemanticAttributes.DB_CONNECTION_STRING]: `redis://${host}:${port}`, | ||
}); | ||
try { | ||
const result = original.apply(this, arguments); | ||
const origResolve = cmd.resolve; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
cmd.resolve = function (result) { | ||
(0, instrumentation_2.safeExecuteInTheMiddle)(() => { var _a; return (_a = config === null || config === void 0 ? void 0 : config.responseHook) === null || _a === void 0 ? void 0 : _a.call(config, span, cmd.name, cmd.args, result); }, e => { | ||
if (e) { | ||
api_1.diag.error('ioredis instrumentation: response hook failed', e); | ||
} | ||
}, true); | ||
(0, utils_1.endSpan)(span, null); | ||
origResolve(result); | ||
}; | ||
const origReject = cmd.reject; | ||
cmd.reject = function (err) { | ||
(0, utils_1.endSpan)(span, err); | ||
origReject(err); | ||
}; | ||
return result; | ||
} | ||
catch (error) { | ||
(0, utils_1.endSpan)(span, error); | ||
throw error; | ||
} | ||
}; | ||
} | ||
_traceConnection(original) { | ||
const instrumentation = this; | ||
return function () { | ||
const config = instrumentation.getConfig(); | ||
const hasNoParentSpan = api_1.trace.getSpan(api_1.context.active()) === undefined; | ||
if ((config === null || config === void 0 ? void 0 : config.requireParentSpan) === true && hasNoParentSpan) { | ||
return original.apply(this, arguments); | ||
} | ||
const span = instrumentation.tracer.startSpan('connect', { | ||
kind: api_1.SpanKind.CLIENT, | ||
attributes: { | ||
[semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: semantic_conventions_1.DbSystemValues.REDIS, | ||
[semantic_conventions_1.SemanticAttributes.DB_STATEMENT]: 'connect', | ||
}, | ||
}); | ||
const { host, port } = this.options; | ||
span.setAttributes({ | ||
[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: host, | ||
[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: port, | ||
[semantic_conventions_1.SemanticAttributes.DB_CONNECTION_STRING]: `redis://${host}:${port}`, | ||
}); | ||
try { | ||
const client = original.apply(this, arguments); | ||
(0, utils_1.endSpan)(span, null); | ||
return client; | ||
} | ||
catch (error) { | ||
(0, utils_1.endSpan)(span, error); | ||
throw error; | ||
} | ||
}; | ||
} | ||
} | ||
exports.IORedisInstrumentation = IORedisInstrumentation; | ||
//# sourceMappingURL=instrumentation.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.35.2"; | ||
export declare const VERSION = "0.35.3"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.35.2'; | ||
exports.VERSION = '0.35.3'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-ioredis", | ||
"version": "0.35.2", | ||
"version": "0.35.3", | ||
"description": "OpenTelemetry ioredis automatic instrumentation package.", | ||
@@ -41,6 +41,3 @@ "main": "build/src/index.js", | ||
"build/src/**/*.js.map", | ||
"build/src/**/*.d.ts", | ||
"doc", | ||
"LICENSE", | ||
"README.md" | ||
"build/src/**/*.d.ts" | ||
], | ||
@@ -56,3 +53,3 @@ "publishConfig": { | ||
"@opentelemetry/context-async-hooks": "^1.8.0", | ||
"@opentelemetry/contrib-test-utils": "^0.34.2", | ||
"@opentelemetry/contrib-test-utils": "^0.34.3", | ||
"@opentelemetry/sdk-trace-base": "^1.8.0", | ||
@@ -74,3 +71,3 @@ "@opentelemetry/sdk-trace-node": "^1.8.0", | ||
"dependencies": { | ||
"@opentelemetry/instrumentation": "^0.44.0", | ||
"@opentelemetry/instrumentation": "^0.45.1", | ||
"@opentelemetry/redis-common": "^0.36.1", | ||
@@ -81,3 +78,3 @@ "@opentelemetry/semantic-conventions": "^1.0.0", | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-ioredis#readme", | ||
"gitHead": "a8c225d2febcac561a70ca586d3efd5a84f9f3fa" | ||
"gitHead": "607d375595da3ab51b7f773ac360900121c4361b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55673
344
+ Added@opentelemetry/instrumentation@0.45.1(transitive)
- Removed@opentelemetry/instrumentation@0.44.0(transitive)