Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Oct 5, 2020
1 parent 6b430bb commit d8dee60
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
22 changes: 19 additions & 3 deletions packages/kbn-apm-config-loader/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ const getDefaultConfig = (isDistributable: boolean): ApmAgentConfig => {
return {
active: false,
globalLabels: {},
// Do not use a centralized controlled config
centralConfig: false,
captureHeaders: false,
captureBody: false,
// Capture all exceptions that are not caught
logUncaughtExceptions: true,
// Can be performance intensive, disabling by default
breakdownMetrics: false,
};
}

Expand Down Expand Up @@ -81,7 +83,8 @@ export class ApmConfiguration {
const apmConfig = merge(
getDefaultConfig(this.isDistributable),
this.getConfigFromKibanaConfig(),
this.getDevConfig()
this.getDevConfig(),
this.getDistConfig()
);

const rev = this.getGitRev();
Expand Down Expand Up @@ -130,6 +133,19 @@ export class ApmConfiguration {
}
}

/** Config keys that cannot be overridden in production builds */
private getDistConfig(): ApmAgentConfig {
if (!this.isDistributable) {
return {};
}

return {
// Headers & body may contain sensitive info
captureHeaders: false,
captureBody: 'off',
};
}

private getGitRev() {
if (this.isDistributable) {
return this.pkgBuild.sha;
Expand Down
14 changes: 9 additions & 5 deletions src/apm.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ module.exports = function (serviceName = name) {
const conf = apmConfig.getConfig(serviceName);
const apm = require('elastic-apm-node');

// Filter out username PII
// Filter out all user PII
apm.addFilter((payload) => {
if (payload.context && payload.context.user && payload.context.user.username) {
delete payload.context.user.username;
try {
if (payload.context && payload.context.user && typeof payload.context.user === 'object') {
Object.keys(payload.context.user).forEach((key) => {
payload.context.user[key] = '[REDACTED]';
});
}
} finally {
return payload;
}

return payload;
});

apm.start(conf);
Expand Down

0 comments on commit d8dee60

Please sign in to comment.