UNPKG

dd-trace

Version:

Datadog APM tracing client for JavaScript

42 lines (33 loc) 1.26 kB
'use strict' const tx = require('../../dd-trace/src/plugins/util/redis') function createWrapSendCommand (tracer, config) { return function wrapSendCommand (sendCommand) { return function sendCommandWithTrace (command, stream) { if (!command || !command.promise || !config.filter(command.name)) return sendCommand.apply(this, arguments) const options = this.options || {} const connectionName = this.options.connectionName const db = options.db const span = tx.instrument(tracer, config, db, command.name, command.args) tx.setHost(span, options.host, options.port) tx.wrap(span, command.promise) if (config.splitByInstance && connectionName) { const service = config.service ? `${config.service}-${connectionName}` : connectionName span.setTag('service.name', service) } return tracer.scope().bind(sendCommand, span).apply(this, arguments) } } } module.exports = { name: 'ioredis', versions: ['>=2'], patch (Redis, tracer, config) { config = tx.normalizeConfig(config) this.wrap(Redis.prototype, 'sendCommand', createWrapSendCommand(tracer, config)) }, unpatch (Redis) { this.unwrap(Redis.prototype, 'sendCommand') } }