How to use the elastic-apm-node.isStarted 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 posquit0 / koa-rest-api-boilerplate / app / middlewares / apm.js View on Github external
return async function apmMiddleware(ctx, next) {
    // Skip if apm is disabled
    if (!apm.isStarted()) {
      debug('Skipped because APM is disabled');
      return await next();
    }

    try {
      await next();
    } catch (err) {
      // Sending error when response is sent
      ctx.res.on('finish', () => {
        apm.captureError(err);

        debug('Sent error to APM server');
      });
      throw err;
    } finally {
      // Set custom context data