-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add filtering support for metadata payload #1916
Comments
Some quick notes and a first hack:
diff --git a/index.js b/index.js
index c27fb71..2bb3a0d 100644
--- a/index.js
+++ b/index.js
@@ -495,7 +495,9 @@ function onStream (client, onerror) {
// All requests to the APM Server must start with a metadata object
if (!client._encodedMetadata) {
- client._encodedMetadata = client._encode({ metadata: client._conf.metadata }, Client.encoding.METADATA)
+ // XXX HACK: This should be done *once*, but as late as possible.
+ var filteredMetadata = client._conf.metadataFilters.process(client._conf.metadata)
+ client._encodedMetadata = client._encode({ metadata: filteredMetadata }, Client.encoding.METADATA)
}
stream.write(client._encodedMetadata)
}
diff --git a/lib/agent.js b/lib/agent.js
index cd75056..56038c1 100644
--- a/lib/agent.js
+++ b/lib/agent.js
@@ -42,6 +42,7 @@ function Agent () {
this._errorFilters = new Filters()
this._transactionFilters = new Filters()
this._spanFilters = new Filters()
+ this._metadataFilters = new Filters()
this._transport = null
this.lambda = lambda(this)
@@ -221,6 +224,12 @@ Agent.prototype.addFilter = function (fn) {
this.addErrorFilter(fn)
this.addTransactionFilter(fn)
this.addSpanFilter(fn)
+ // XXX Decide if this would be a breaking change. For example the *default
+ // filter example in the docs* will break because it assumes
+ // `payload.context`. However that should *already* break for filtering
+ // error payloads.
+ // https://www.elastic.co/guide/en/apm/agent/nodejs/current/agent-api.html#apm-add-filter
+ this.addMetadataFilter(fn)
}
Agent.prototype.addErrorFilter = function (fn) {
@@ -250,6 +259,15 @@ Agent.prototype.addSpanFilter = function (fn) {
this._spanFilters.push(fn)
}
+Agent.prototype.addMetadataFilter = function (fn) {
+ if (typeof fn !== 'function') {
+ this.logger.error('Can\'t add filter of type %s', typeof fn)
+ return
+ }
+
+ this._metadataFilters.push(fn)
+}
+
Agent.prototype.captureError = function (err, opts, cb) {
if (typeof opts === 'function') return this.captureError(err, null, opts)
diff --git a/lib/config.js b/lib/config.js
index 2702181..e69e6f5 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -253,6 +253,7 @@ class Config {
globalLabels: maybePairsToObject(conf.globalLabels),
hostname: conf.hostname,
environment: conf.environment,
+ metadataFilters: agent._metadataFilters,
// Sanitize conf
truncateKeywordsAt: config.INTAKE_STRING_MAX_SIZE,
apm.addMetadataFilter(function myFilt(payload) {
if (payload.process && payload.process.argv) {
const user = new RegExp(process.env.USER, 'g')
payload.process.argv = payload.process.argv.map((arg) => {
return arg.replace(user, '[REDACTED]')
})
}
return payload
}) and then observe that filtering in traffic to apm-server:
|
Notes:
|
@joshdover Would your use case be handled with a config option to fully disable including process args in the "metadata"? I ask because the Java APM agent has a If this handles your use case, it would be faster as well. @tylersmalley I noticed you +1'd this above. Do you have a different use case that would be better served with a Currently my preference is to:
|
I don't think the process args are the only place that the full path is included, which is the issue since it includes the username. |
@tylersmalley Thanks! You are right. |
Much appreciated, thanks!! |
This will be in v3.14.0 of the agent, which we hope to release early next week. |
In Kibana's APM instrumentation, we are now capturing stats from developer's local environments. One issue is that we cannot filter some PII such as the developer's username from the path that is contained in the
process.args
array in the metadata that is sent along with APM traces:Currently, we're including a notice that some personal data may be captured with an option for disabling this. Ideally, we'd be able filter this out similar to how we can filter out transaction data.
The text was updated successfully, but these errors were encountered: