HRQB 39 - Remove sensitive data from Sentry events #102
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose and background context
HRQBClient deals with sensitive data that comes from the data warehouse. Sentry is useful for alerting us when there are issues, and it provides a lot of context about the incident (e.g. a python
Exception
). In this context, by default, all variables in scope at the moment are also included. This could result in a Sentry event that has PII information because variables are in scope, even if they have nothing do to directly with the exception.While we have filtering on Sentry's side after the data has been recieved, this PR removes sensitive data from events before data is sent to Sentry. This is achieved by using the
before_send
callback in `sentry_sdk.init().A couple things of note:
There is both a
sentry_before_send_callback()
function (registered as the callback) and a_remove_sensitive_scope_variables()
function, which is called by the former. This allows easier testing of_remove_sensitive_scope_variables()
, where it is not directly registered by the Sentry SDK and therefore harder to mock.Second, the test
test_sentry_scope_variables_removed_from_sent_event
is worth looking at. This utilizes the librarypytest-mock
, which was new to me, as this provides a convenience "spy" functionality on traditional mocks. This allows looking at the returned value of a mocked object, without modifying the object's behavior at all. I anticipate using this in future tests as well, in this project and beyond.Includes new or updated dependencies?
YES
Changes expectations for external applications?
YES: data will be filtered from events before sending to Sentry
What are the relevant tickets?
Developer
Code Reviewer(s)