|
6 | 6 | - Support for Rails ActiveSupport log subscribers ([#2690](https://github.com/getsentry/sentry-ruby/pull/2690)) |
7 | 7 | - Support for defining custom Rails log subscribers that work with Sentry Structured Logging ([#2689](https://github.com/getsentry/sentry-ruby/pull/2689)) |
8 | 8 |
|
| 9 | + Rails applications can now define custom log subscribers that integrate with Sentry's structured logging system. The feature includes built-in subscribers for ActionController, ActiveRecord, ActiveJob, and ActionMailer events, with automatic parameter filtering that respects Rails' `config.filter_parameters` configuration. |
| 10 | + |
| 11 | + To enable structured logging with Rails log subscribers: |
| 12 | + |
| 13 | + ```ruby |
| 14 | + Sentry.init do |config| |
| 15 | + # ... your setup ... |
| 16 | + |
| 17 | + # Make sure structured logging is enabled |
| 18 | + config.enable_logs = true |
| 19 | + |
| 20 | + # Enable default Rails log subscribers (ActionController and ActiveRecord) |
| 21 | + config.rails.structured_logging.enabled = true |
| 22 | + end |
| 23 | + ``` |
| 24 | + |
| 25 | + To configure all subscribers: |
| 26 | + |
| 27 | + ```ruby |
| 28 | + Sentry.init do |config| |
| 29 | + # ... your setup ... |
| 30 | + |
| 31 | + # Make sure structured logging is enabled |
| 32 | + config.enable_logs = true |
| 33 | + |
| 34 | + # Enable Rails log subscribers |
| 35 | + config.rails.structured_logging.enabled = true |
| 36 | + |
| 37 | + # Add ActionMailer and ActiveJob subscribers |
| 38 | + config.rails.structured_logging.subscribers.update( |
| 39 | + action_mailer: Sentry::Rails::LogSubscribers::ActionMailerSubscriber, |
| 40 | + active_job: Sentry::Rails::LogSubscribers::ActiveJobSubscriber |
| 41 | + ) |
| 42 | + end |
| 43 | + ``` |
| 44 | + |
| 45 | + You can also define custom log subscribers by extending the base class: |
| 46 | + |
| 47 | + ```ruby |
| 48 | + class MyCustomSubscriber < Sentry::Rails::LogSubscriber |
| 49 | + attach_to :my_component |
| 50 | + |
| 51 | + def my_event(event) |
| 52 | + log_structured_event( |
| 53 | + message: "Custom event occurred", |
| 54 | + level: :info, |
| 55 | + attributes: { duration_ms: event.duration } |
| 56 | + ) |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + Sentry.init do |config| |
| 61 | + # ... your setup ... |
| 62 | + |
| 63 | + # Make sure structured logging is enabled |
| 64 | + config.enable_logs = true |
| 65 | + |
| 66 | + # Enable Rails log subscribers |
| 67 | + config.rails.structured_logging.enabled = true |
| 68 | + |
| 69 | + # Add custom subscriber |
| 70 | + config.rails.structured_logging.subscribers[:my_component] = MyCustomSubscriber |
| 71 | + end |
| 72 | + ``` |
| 73 | + |
9 | 74 | ### Internal |
10 | 75 |
|
11 | 76 | - Factor out do_request in HTTP transport ([#2662](https://github.com/getsentry/sentry-ruby/pull/2662)) |
|
0 commit comments