Skip to content

Exception data is lost in active support instrumentation events #1629

@Linuus

Description

@Linuus

Issue Description

I'm having some issues using Sentry, ActiveJob and LogSubscribers.
We have an ActiveJob log subscriber which logs stuff in production. When an exception occurs in a job, we log it and the instrumentation event payload includes the Exception that was raised.
However, now that we are trying to move over to Sentry, the exception is no longer present in the instrumentation event payload. The reason for this is that here:
https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/lib/sentry/rails/active_job.rb#L36-L39

All exceptions are rescued. The exception is only re-raised if there are no handlers for it. In our case, we have a retry_on handler so the error won't be re-raised. The issue with this though is that ActiveSupport::Notifications::Instrumenter is also rescuing any exceptions that happen and adds the exception information to the event payload, here: https://github.com/rails/rails/blob/8337645e852c7a2f4f112ea03db6fa4e00081c5e/activesupport/lib/active_support/notifications/instrumenter.rb#L25-L27
So, now that Sentry is rescuing the exception, AS instrumenter doesn't get any exception and we lose that information.

This is what the order of "rescues" are:

Is this expected behavior?

Reproduction Steps

Add an active job log subscriber and log event.payload[:exception]
Add a job that has a retry_on handler.
Raise an error in the job that is handled by the retry_on handler.

Expected Behavior

The exception is logged in the log subscriber.

Actual Behavior

The exception is not logged in the log subscriber.

Ruby Version

2.7.3

SDK Version

4.8.0

Integration and Its Version

Sentry Rails 4.8.0

Sentry Config

No response

Metadata

Metadata

Assignees

Labels

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions