How to use the elastic-apm-node.addFilter 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
phoneNumber: user.phoneNumber,
    gender: user.gender
  };
}

function redactAuthHeaders(payload) {
  if (payload.context && payload.context.request && payload.context.request.headers) {
    const headers = payload.context.request.headers;
    if (headers['x-authenticated-userid']) {
      headers['x-authenticated-userid'] = '[REDACTED]';
    }
  }
  return payload;
}

apm.addFilter(redactAuthHeaders);

/**
 * Return middleware that enhance the transaction data which will be sent
 * to APM Server.
 *
 * @param {Object} options={} - Optional configuration.
 * @return {function} Koa middleware.
 */
module.exports = () => {
  debug('Create a middleware');

  return async function apmMiddleware(ctx, next) {
    // Skip if apm is disabled
    if (!apm.isStarted()) {
      debug('Skipped because APM is disabled');
      return await next();
github vpdb / server / src / app / server.ts View on Github external
private setupApmFilter() {
		const apm = require('elastic-apm-node');
		apm.addFilter((payload: any) => {

			if (!payload.context) {
				return payload;
			}

			if (payload.context.response && payload.context.response.headers) {
				if (payload.context.response.headers['x-token-refresh']) {
					payload.context.response.headers['x-token-refresh'] = '[REDACTED]';
				}
			}
			if (payload.context.request && payload.context.request.body) {
				if (payload.context.request.body.password) {
					payload.context.request.body.password = '[REDACTED]';
				}
				if (payload.context.request.body.current_password) {
					payload.context.request.body.current_password = '[REDACTED]';