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
Appendix: Available Event Attributes
Basic Information
-
event.level
— Severity level (e.g.,:error
,:warning
,:info
) -
event.message
— Custom message string -
event.timestamp
— When the event occurred
Exception Details
-
hint[:exception]
— The original exception object -
hint[:exception].class
— Exception class name -
hint[:exception].message
— Exception message -
hint[:exception].backtrace
— Full stack trace
Context & Metadata
-
event.tags
— Hash of custom tags -
event.user
— User context (id, email, username, ip_address) -
event.transaction
— Transaction/request name -
event.contexts
— Additional context (os, runtime, trace)
Background Job Information
-
event.extra[:active_job]
— ActiveJob class name -
event.extra[:job_id]
— Job ID -
event.extra[:arguments]
— Job arguments array -
event.tags[:rake_task]
— Rake task name (if from rake)
Request Information (when applicable)
-
event.request
— Request details (url, method, headers, query_string, cookies, data) -
event.request.url
— Full request URL -
event.request.method
— HTTP method
Additional Data
-
event.breadcrumbs
— Array of breadcrumb events leading up to the error -
event.extra
— Hash of additional custom data -
event.fingerprint
— Array used for grouping events -
event.environment
— Environment name
Posted by Felix Eschey to makandra dev (2025-10-23 06:44)