Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async send (...args) {
const sendParams = args[0] || {}
const name = `Requester send: ${this.advertisement.name} | type: ${sendParams.type}`
const apmSpan = apm.startSpan(name)
// used to link to the source APM transaction across network (see custom responder)
if (apm.currentTransaction) {
sendParams._apmTraceparent = apm.currentTransaction.traceparent
}
try {
const result = await super.send(...args)
return result
} finally {
if (isApmActive && !apmSpan) {
if (!apm.currentTransaction) {
logError(new Error(`No APM transaction available in requester "${name}"`))
} else {
logError(new Error(`Empty apm span in requester "${name}"`))
}
}
// check the existence of apm span just in case (should always be defined)
async send (...args) {
const sendParams = args[0] || {}
const name = `Requester send: ${this.advertisement.name} | type: ${sendParams.type}`
const apmSpan = apm.startSpan(name)
// used to link to the source APM transaction across network (see custom responder)
if (apm.currentTransaction) {
sendParams._apmTraceparent = apm.currentTransaction.traceparent
}
try {
const result = await super.send(...args)
return result
} finally {
if (isApmActive && !apmSpan) {
if (!apm.currentTransaction) {
logError(new Error(`No APM transaction available in requester "${name}"`))
} else {
logError(new Error(`Empty apm span in requester "${name}"`))
}
}
// check the existence of apm span just in case (should always be defined)
apmSpan && apmSpan.end()
function newAgent() {
agent.currentTransaction = undefined;
agent.currentSpan = undefined;
agent.currentTraceparent = undefined;
agent.captureError = jest.fn();
agent.startSpan = jest.fn(() => ({
end: jest.fn()
}));
agent.startTransaction = jest.fn(() => ({
end: jest.fn()
}));
return agent;
}