"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.initApm = void 0; var _config_loader = require("./config_loader"); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ const initApm = (argv, rootDir, isDistributable, serviceName) => { const apmConfigLoader = (0, _config_loader.loadConfiguration)(argv, rootDir, isDistributable); const apmConfig = apmConfigLoader.getConfig(serviceName); // we want to only load the module when effectively used // eslint-disable-next-line @typescript-eslint/no-var-requires const apm = require('elastic-apm-node'); // Filter out all user PII apm.addFilter(payload => { try { var _payload$context; if ((_payload$context = payload.context) !== null && _payload$context !== void 0 && _payload$context.user && typeof payload.context.user === 'object') { Object.keys(payload.context.user).forEach(key => { payload.context.user[key] = '[REDACTED]'; }); } } catch (e) { // just silently ignore the error } return payload; }); apm.start(apmConfig); }; exports.initApm = initApm;