Skip to content

Commit

Permalink
Filter out cookie banner JS errors from Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
steventux committed Jun 19, 2024
1 parent 94d72d4 commit 492d00d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion config/initializers/sentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"NetworkError when attempting to fetch resource.",
].freeze

def cookie_banner_js_event?(event, hint)
hint[:exception].is_a?(Error) &&
tags[:mechanism] == "onunhandledrejection" &&
event.exception.values.any? { |ex| ex.value.include?("[object Response]") }
end

def filterable_js_event?(event, hint)
hint[:exception].is_a?(TypeError) && event.exception.values.any? do |exception|
FILTERABLE_JS_ERRORS.include?(exception.value)
Expand All @@ -19,7 +25,7 @@ def filterable_js_event?(event, hint)

filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters)
config.before_send = lambda do |event, hint|
return nil if filterable_js_event?(event, hint)
return nil if filterable_js_event?(event, hint) || cookie_banner_js_event?(event, hint)

# use Rails' parameter filter to sanitize the event
filter.filter(event.to_hash)
Expand Down

0 comments on commit 492d00d

Please sign in to comment.