Skip to content

Commit 1a19c30

Browse files
committed
fix: Use around_perform to capture ActiveJob errors.
1 parent ec8dc87 commit 1a19c30

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

app/jobs/application_job.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ class ApplicationJob < ActiveJob::Base
66
# discard_on ActiveJob::DeserializationError
77

88
# Make sure to capture and record any exceptions that occur in jobs.
9-
rescue_from(Exception) do |error|
9+
# Uses around_perform rather than rescue_from so that the OTel span is still
10+
# open when we annotate it — rescue_from runs after the instrumentation has
11+
# already ended the span.
12+
around_perform do |_job, block|
13+
block.call
14+
rescue Exception => error # standard:disable Lint/RescueException
1015
span = OpenTelemetry::Trace.current_span
1116
span.status = OpenTelemetry::Trace::Status.error(error.message)
1217
span.set_attribute("job.class", self.class.name)
@@ -19,7 +24,6 @@ class ApplicationJob < ActiveJob::Base
1924
error
2025
)
2126

22-
# Re-raise the exception to be handled by the job framework (SolidQueue).
23-
raise error
27+
raise
2428
end
2529
end

0 commit comments

Comments
 (0)