sentry-ruby icon indicating copy to clipboard operation
sentry-ruby copied to clipboard

Excluded Exceptions list does not play nice with Puma Auto Reload mechanism - dev environment issue

Open cgaube opened this issue 1 year ago • 3 comments
trafficstars

Issue Description

https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/lib/sentry/configuration.rb#L595-L600

This comparison function returns false as soon as the puma server is auto reloaded - (when you change a file in your dev environment) because the reloaded class id will be different

Instead of using ===. we should probably compare the NAME of the exception

excluded_exception_class.to_s === cause.to_s

Reproduction Steps

--enable debugging logger

  • Start puma in dev mode
  • manually trigger and exception anywhere in your code

notice that the exception is ignored User excluded error: XXXXX

  • change a file, any file, puma hot relad
  • go trigger the exception once again -> the error will be sent to Sentry

Expected Behavior

exceptions are ALWAYS excluded

Actual Behavior

after hot reload exceptions are sent to sentry

Ruby Version

3.2.2

SDK Version

5.15

Integration and Its Version

No response

Sentry Config

No response

cgaube avatar Jan 12 '24 23:01 cgaube

hmm @st0012 do you have an opinion here?

sl0thentr0py avatar Jan 15 '24 12:01 sl0thentr0py

I think he means the Rails autoloader, not the puma autoloader.

nerdrew avatar Jan 16 '24 18:01 nerdrew

I can't reproduce the issue:

# config/initializers/sentry.rb
class FooException < StandardError
end

Sentry.init do |config|
  # ....
  config.excluded_exceptions += ['FooException']
  config.logger = Logger.new($stdout)
  config.logger.level = :debug
end

And in the PostsController, I raise the exception with raise FooException.

Here's the logs for 2 requests:

Started GET "/posts/new" for 127.0.0.1 at 2024-02-04 12:31:05 +0000
D, [2024-02-04T12:31:05.702860 #72341] DEBUG -- sentry: [Tracing] Starting <http.server> transaction </posts/new>
  ActiveRecord::SchemaMigration Pluck (0.1ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
# ---------------------------------------
# I added this log to verify the file is reloaded by Rails
# ---------------------------------------
Loading /Users/hung-wulo/src/github.com/getsentry/sentry-ruby/sentry-rails/examples/rails-7.0/app/controllers/posts_controller.rb...
Processing by PostsController#new as HTML
Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms | Allocations: 1830)


  
FooException (FooException):
  
app/controllers/posts_controller.rb:25:in `new'
# ---------------------------------------
# The error is excluded by the SDK
# ---------------------------------------
D, [2024-02-04T12:31:05.885561 #72341] DEBUG -- sentry: User excluded error: #<FooException: FooException>
I, [2024-02-04T12:31:05.886686 #72341]  INFO -- sentry: [Transport] Sending envelope with items [transaction] 1c648774e4f8423fb0e82b60975f4c8d to Sentry
Started GET "/posts/new" for 127.0.0.1 at 2024-02-04 12:31:15 +0000
D, [2024-02-04T12:31:15.838721 #72341] DEBUG -- sentry: [Tracing] Starting <http.server> transaction </posts/new>
# ---------------------------------------
# I added this log to verify the file is reloaded by Rails
# ---------------------------------------
Loading /Users/hung-wulo/src/github.com/getsentry/sentry-ruby/sentry-rails/examples/rails-7.0/app/controllers/posts_controller.rb...
Processing by PostsController#new as HTML
Completed 500 Internal Server Error in 7ms (ActiveRecord: 0.4ms | Allocations: 7040)


  
FooException (FooException):
  
app/controllers/posts_controller.rb:26:in `new'
# ---------------------------------------
# After reloading, the error is excluded by the SDK again
# ---------------------------------------
D, [2024-02-04T12:31:16.000178 #72341] DEBUG -- sentry: User excluded error: #<FooException: FooException>
I, [2024-02-04T12:31:16.000869 #72341]  INFO -- sentry: [Transport] Sending envelope with items [transaction] 21f07bf4adc749e08e200e9d3a0d4574 to Sentry
I, [2024-02-04T12:32:05.955211 #72341]  INFO -- sentry: [Transport] Sending envelope with items [sessions]  to Sentry

I also don't think reloading the same class will make === fail as it'd be a major problem for many applications. One exception could be if the class is anonymous and is generated dynamically. But in that case I don't think it's possible to add them to the excluded_exceptions list.

Can you provide a more detailed example so we can investigate this further? Thank you 😄

st0012 avatar Feb 04 '24 12:02 st0012