How to use the elastic-apm-node.captureError 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 / logger.js View on Github external
// If additional properties are stored into Error object, like in InternalAvailability model:
    // `throw createError(`Unfound asset type (ID ${asset.assetTypeId})`, { assetTypeId: asset.assetTypeId })`
    // Without errorData, we lose `assetTypeId` information, because `apm.captureError()` won't store it
    let errorData
    if (error instanceof Error) {
      const omittedErrorFields = [
        'message',
        'stack',
        'statusCode',
        'expose'
      ]
      errorData = _.pick(error, _.difference(Object.keys(error), omittedErrorFields))
    }

    // passed context overrides default context properties
    apm.captureError(error, {
      user: removeUndefinedValues(newUser),
      custom: removeUndefinedValues(Object.assign({ errorData }, newCustom)),
      labels: removeUndefinedValues(newLabels),
      message
    })
  }
}
github stelace / stelace / src / services / workflow.js View on Github external
}).then(lastLog => {
            if (workflow.notifyUrl) {
              return notifyAfterCompleted({
                workflow,
                lastLog,
                event,
                exposedEvent,
                WorkflowLog,
                runId,
                platformId,
                env
              })
            }
          })
        } catch (err) {
          apm.captureError(err)

          logError(err.response ? err.response.body : err, {
            platformId,
            env,
            custom: {
              workflowId: currentWorkflowId.id,
              eventId: event.id,
              runId
            },
            message: 'Fail to execute stelace workflow'
          })
        } finally {
          if (apmSpans.allRuns) apmSpans.allRuns.end()
          apmSpans = {} // clean for garbage collection
          singleWorkflowTransaction.end()
        }
github alphagov / paas-admin / src / components / errors / error.ts View on Github external
export function internalServerErrorMiddleware(err: Error, req: any, res: express.Response, next: express.NextFunction) {
  req.log.error(err);
  apm.captureError(err);

  if (err instanceof NotFoundError) {
    return pageNotFoundMiddleware(req, res, next);
  }

  if (err instanceof UserFriendlyError) {
    res.status(500);
    res.send(internalServerError.render({
      errorMessage: err.message,
      location: platformLocation(process.env.AWS_REGION || /* istanbul ignore next */ ''),
    }));

    return;
  }

  res.status(500);
github posquit0 / koa-rest-api-boilerplate / app / middlewares / apm.js View on Github external
ctx.res.on('finish', () => {
        apm.captureError(err);

        debug('Sent error to APM server');
      });
      throw err;