Sentry Local Logging in Ruby

Updated . Posted . Visible to the public.

Enable local logging for Sentry when:

  • Debugging Sentry event capture locally
  • Testing error handling without polluting production metrics
  • Developing background jobs and want to see what Sentry captures

How to enable

To capture and log Sentry events locally during development without sending to the server, add this to config/initializers/sentry.rb inside the Sentry.init block:

if Rails.env.development?
  # Use dummy transport to prevent actual transmission to Sentry
  config.transport.transport_class = Sentry::DummyTransport
  config.background_worker_threads = 0

  # Log events locally before dummy transport processes them
  config.before_send = lambda do |event, hint|
    log_sentry_event(event, hint)
    event # Return event so it can be processed by dummy DummyTransport
  end
end

Then add this helper method after the Sentry.set_tags block:

def log_sentry_event(event, hint)
  Rails.logger.error('SENTRY EVENT CAPTURED (LOCAL ONLY)')
  
  # Log anything that is interesting to you about the Sentry event
  # See appendix below for available event attributes
end
  • DummyTransport — Prevents actual HTTP transmission to Sentry servers; events are captured locally but not sent
  • background_worker_threads = 0 — Disables async processing; events process synchronously in development for immediate capture
  • before_send callback — Lambda hook that intercepts events right before transport; allows local logging/processing before dummy transport processes it
Profile picture of Felix Eschey
Felix Eschey
Last edit
Felix Eschey
Keywords
Ruby, on, Rails
License
Source code in this card is licensed under the MIT License.
Posted by Felix Eschey to makandra dev (2025-10-23 06:44)