function wrapFactory (tracers, command) {
return function (original) {
return function mongoOperationTrace (ns, ops, options, callback) {
const operationName = `${OPERATION_NAME}_${command}`
const statement = JSON.stringify(ops)
const spans = tracers.map((tracer) => cls.startChildSpan(tracer, operationName, {
tags: {
[Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT,
[Tags.DB_TYPE]: DB_TYPE,
[Tags.DB_STATEMENT]: statement,
[Tags.DB_INSTANCE]: ns
}
}))
debug(`Operation started ${operationName}`, {
[Tags.DB_TYPE]: DB_TYPE,
[Tags.DB_STATEMENT]: statement,
[Tags.DB_INSTANCE]: ns
})
if (typeof options === 'function') {
return original.call(this, ns, ops, wrapCallback(tracers, spans, operationName, options))
}
return original.call(this, ns, ops, options, wrapCallback(tracers, spans, operationName, callback))
}
}
}