Skip to content

Commit

Permalink
Merge pull request #5330 from DFE-Digital/fix-sentry
Browse files Browse the repository at this point in the history
Fix Sentry not sending events
  • Loading branch information
ethax-ross authored Nov 25, 2024
2 parents 87bad22 + bd9eb08 commit fb81c13
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions config/initializers/sentry.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
# frozen_string_literal: true

FILTERABLE_JS_ERRORS = [
"Failed to fetch",
"NetworkError when attempting to fetch resource.",
].freeze

def cookie_banner_js_event?(event, hint)
hint[:exception].is_a?(Error) &&
event.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)
end
end

Sentry.init do |config|
config.enabled_environments = %w[production sandbox staging review]
config.dsn = config.enabled_environments.include?(Rails.env) ? Rails.application.credentials.SENTRY_DSN : "disabled"
config.breadcrumbs_logger = %i[active_support_logger http_logger]
config.release = "#{ENV['RELEASE_VERSION']}-#{ENV['SHA']}"

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

config.before_send = lambda do |event|
# use Rails' parameter filter to sanitize the event
filter.filter(event.to_hash)
end
Expand Down

0 comments on commit fb81c13

Please sign in to comment.