Add ErrorTracker.Filter behavior for modifying error context before saving#94
Conversation
|
Thanks @MSE99! I took a quick look and the MR looks fantastic. Will do a deeper review soon. |
| context = get_context() |> Map.merge(given_context) |> filter_context_data() | ||
|
|
||
| if enabled?() && !ignored?(error, context) do | ||
| {_error, occurrence} = upsert_error!(error, stacktrace, context, reason) |
There was a problem hiding this comment.
I think that it may make sense to filter the context data only after we are sure that we want to track the error.
This would reduce the number of operations that the ErrorTracker does for ignored errors, which I think is important given that this calls user-defined code that we don't have any control over.
| context = get_context() |> Map.merge(given_context) |> filter_context_data() | |
| if enabled?() && !ignored?(error, context) do | |
| {_error, occurrence} = upsert_error!(error, stacktrace, context, reason) | |
| context = Map.merge(get_context(), given_context) | |
| if enabled?() && !ignored?(error, context) do | |
| filtered_context = filter_context_data(context) | |
| {_error, occurrence} = upsert_error!(error, stacktrace, filtered_context, reason) |
This would mean that the ignorer, if defined, has access to the full unfiltered context but I think that would be OK as long as we document it.
What do you think @odarriba?
There was a problem hiding this comment.
I agree, as that function may do heavy calculations (or not, who knows)
crbelaus
left a comment
There was a problem hiding this comment.
I'd prefer the filtering to happen only when the error is going to be tracked but this is small concern that should not block this pull request.
I'm going to merge it and then make a small additional change to apply the filtering only when we are sure that the error is going to be tracked.
Thanks @MSE99!
Just a few additions to #94: - We don't need to filter context when not tracking errors - Mention how to filter context in the Getting Started guide
Adds a
ErrorTracker.Filterbehavior that users can supply, it has a single functionsanitize/1that takes an error context and returns a new error context which will be saved in the DB.Closes #88