forked from elastic/apm-agent-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improved filtering function API (elastic#579)
Changes the `agent.addFilter()` function to be called once per event instead of with an array of events. Besides the existing filtering function, three new custom filtering functions have been added: - `agent.addErrorFilter()` - `agent.addTransactionFilter()` - `agent.addSpanFilter()` BREAKING CHANGE: The `agent.addFilter()` API have changed.
- Loading branch information
Showing
16 changed files
with
477 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict' | ||
|
||
const REDACTED = require('./').REDACTED | ||
|
||
const cookie = require('cookie') | ||
const redact = require('redact-secrets')(REDACTED) | ||
const SetCookie = require('set-cookie-serde') | ||
|
||
module.exports = httpHeaders | ||
|
||
function httpHeaders (obj) { | ||
const headers = obj.context && obj.context.request && obj.context.request.headers | ||
|
||
if (!headers) return obj | ||
|
||
if (headers.authorization) headers.authorization = REDACTED | ||
|
||
if (typeof headers.cookie === 'string') { | ||
var cookies = cookie.parse(headers.cookie) | ||
redact.forEach(cookies) | ||
headers.cookie = Object.keys(cookies) | ||
.map(function (k) { return k + '=' + cookies[k] }) | ||
.join('; ') | ||
} | ||
|
||
if (typeof headers['set-cookie'] !== 'undefined') { | ||
try { | ||
var setCookies = new SetCookie(headers['set-cookie']) | ||
redact.forEach(setCookies) | ||
headers['set-cookie'] = stringify(setCookies) | ||
} catch (err) { | ||
// Ignore error | ||
headers['set-cookie'] = '[malformed set-cookie header]' | ||
} | ||
} | ||
|
||
return obj | ||
} | ||
|
||
function stringify (value) { | ||
return Array.isArray(value) | ||
? value.map(value => value.toString()) | ||
: value.toString() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
|
||
module.exports = Filters | ||
|
||
function Filters () { | ||
if (!(this instanceof Filters)) return new Filters() | ||
this._filters = [] | ||
} | ||
|
||
Filters.REDACTED = '[REDACTED]' | ||
|
||
Filters.prototype.add = function (fn) { | ||
this._filters.push(fn) | ||
} | ||
|
||
Filters.prototype.process = function (payload) { | ||
var result = payload | ||
|
||
// abort if a filter function doesn't return an object | ||
this._filters.some(function (filter) { | ||
result = filter(result) | ||
return !result | ||
}) | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.