Skip to content

Instantly share code, notes, and snippets.

@skatkov
Created May 11, 2023 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skatkov/17d1f53d38ea90c4a4c678197e682173 to your computer and use it in GitHub Desktop.
Save skatkov/17d1f53d38ea90c4a4c678197e682173 to your computer and use it in GitHub Desktop.
Store sample of sql when ActiveRecord::QueryCanceled occured
class ApplicationJob < ActiveJob::Base
include ActiveSupport::Rescuable
# PG::QueryCanceled will be wrapped with ActiveRecord::QueryCanceled errors and it's a direct
# descendant of ActiveRecord::StatementInvalid error.
rescue_from ActiveRecord::StatementInvalid do |exception|
# It's hard to know, on which queries we're seeing statement timeouts -- so we are making this explicit in AppSignal error.
Appsignal::Transaction.current.set_sample_data("custom_data", sql_statement: exception.sql)
raise exception
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment