How to use the elastic-apm-node.currentTransaction function in elastic-apm-node

To help you get started, we’ve selected a few elastic-apm-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stelace / stelace / src / cote / CustomRequester.js View on Github external
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)
github stelace / stelace / src / cote / CustomRequester.js View on Github external
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()
github kschingiz / meteor-elastic-apm / __tests__ / mocks / agent.js View on Github external
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;
}