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.

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', () => {

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