-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #683 from bugsnag/v7-redaction
V7: Redaction
- Loading branch information
Showing
10 changed files
with
455 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,27 @@ | ||
const jsonStringify = require('@bugsnag/safe-json-stringify') | ||
const EVENT_FILTER_PATHS = [ | ||
'events.[].app', | ||
const EVENT_REDACTION_PATHS = [ | ||
'events.[].metaData', | ||
'events.[].breadcrumbs', | ||
'events.[].request', | ||
'events.[].device' | ||
] | ||
const SESSION_FILTER_PATHS = [ | ||
'device', | ||
'app', | ||
'user' | ||
'events.[].breadcrumbs.[].metaData', | ||
'events.[].request' | ||
] | ||
|
||
module.exports.event = (event, filterKeys) => { | ||
let payload = jsonStringify(event, null, null, { filterPaths: EVENT_FILTER_PATHS, filterKeys }) | ||
module.exports.event = (event, redactedKeys) => { | ||
let payload = jsonStringify(event, null, null, { redactedPaths: EVENT_REDACTION_PATHS, redactedKeys }) | ||
if (payload.length > 10e5) { | ||
event.events[0]._metadata = { | ||
notifier: | ||
`WARNING! | ||
Serialized payload was ${payload.length / 10e5}MB (limit = 1MB) | ||
metadata was removed` | ||
} | ||
payload = jsonStringify(event, null, null, { filterPaths: EVENT_FILTER_PATHS, filterKeys }) | ||
payload = jsonStringify(event, null, null, { redactedPaths: EVENT_REDACTION_PATHS, redactedKeys }) | ||
if (payload.length > 10e5) throw new Error('payload exceeded 1MB limit') | ||
} | ||
return payload | ||
} | ||
|
||
module.exports.session = (event, filterKeys) => { | ||
const payload = jsonStringify(event, null, null, { filterPaths: SESSION_FILTER_PATHS, filterKeys }) | ||
module.exports.session = (event, redactedKeys) => { | ||
const payload = jsonStringify(event, null, null) | ||
if (payload.length > 10e5) throw new Error('payload exceeded 1MB limit') | ||
return payload | ||
} |
Oops, something went wrong.