Skip to content

Event not sent when scrubbing sensitive data in before_send on sentry-ruby 5.22.2 #2526

@davidwessman

Description

@davidwessman

Issue Description

  • We have some tests checking our filtering before sending data to Sentry.
  • When upgrading to 5.22.2 we no longer get any events in our tests

Our filtering matches the documentation
https://docs.sentry.io/platforms/ruby/guides/rails/data-management/sensitive-data/#scrubbing-data

I think this change is the culprit.

Reproduction Steps

config/initializers/sentry.rb

SENTRY_FILTER = %i[
  identification_number
  ...
]

Sentry.init do |config|
  # https://docs.sentry.io/platforms/ruby/guides/rails/data-management/sensitive-data/#scrubbing-data
  filter = ActiveSupport::ParameterFilter.new(
    SENTRY_FILTER
  )

  config.before_send = lambda do |event, hint|
    filter.filter(event.to_hash)
  end
end
require "test_helper"
require "sentry/test_helper"

class SentryTest < ActiveSupport::TestCase
  include Sentry::TestHelper

  setup do
    setup_sentry_test
  end

  test "exception sends to Sentry" do
    exception = RuntimeError.new("This is a test")
    Sentry.capture_exception(exception)

    event = last_sentry_event # this returns nil on 5.22.2
    message = event[:exception][:values][0][:value]

    assert_match(/This is a test/, message)
  end
end

Expected Behavior

before_send filter should still be valid (or another way to write it)

Actual Behavior

before_send returns hash and therefore it will not send

Ruby Version

3.3.7

SDK Version

5.22.2

Integration and Its Version

Rails 7.1, Sidekiq 7.3.8

Sentry Config

Minimal example that reproduces the error

SENTRY_FILTER = %i[
  body
  identification_number
]

Sentry.init do |config|
  # https://docs.sentry.io/platforms/ruby/guides/rails/data-management/sensitive-data/#scrubbing-data
  filter = ActiveSupport::ParameterFilter.new(
    SENTRY_FILTER
  )

  config.before_send = lambda do |event, hint|
    filter.filter(event.to_hash)
  end
end

Metadata

Metadata

Assignees

Labels

No fields configured for issues without a type.

Projects

Status

Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions