Class: PostHog::Rails::Configuration
- Inherits:
-
Object
- Object
- PostHog::Rails::Configuration
- Defined in:
- lib/posthog/rails/configuration.rb
Constant Summary collapse
- DEFAULT_LOGS_MAX_RECORDS_PER_MINUTE =
Default cap on log records forwarded to PostHog Logs per minute.
6_000
Instance Attribute Summary collapse
-
#auto_capture_exceptions ⇒ Boolean
Whether to automatically capture exceptions from Rails.
-
#auto_instrument_active_job ⇒ Boolean
Whether to automatically instrument ActiveJob.
-
#capture_user_context ⇒ Boolean
Whether to capture the current user context in exceptions.
-
#current_user_method ⇒ Symbol
Method name to call on controller to get the current user.
-
#excluded_exceptions ⇒ Array<String>
Exception class names to ignore in addition to the defaults.
-
#logs_before_send ⇒ Proc?
Callback invoked with each log record hash (:timestamp, :severity, :body, :attributes — where :severity is a symbol such as :warn) before it is sent to PostHog Logs.
-
#logs_enabled ⇒ Boolean
Master switch for forwarding logs to PostHog Logs over OTLP.
-
#logs_forward_rails_logger ⇒ Boolean
Whether to broadcast Rails.logger output into the PostHog Logs sink.
-
#logs_level ⇒ Integer, ...
Minimum severity to forward to PostHog Logs.
-
#logs_max_records_per_minute ⇒ Integer, ...
Maximum log records forwarded to PostHog Logs per minute, protecting the ingestion quota from runaway log volume.
-
#report_rescued_exceptions ⇒ Boolean
Whether to capture exceptions that Rails rescues (e.g., with rescue_from).
-
#use_tracing_headers ⇒ Boolean
Whether to use PostHog tracing headers for request-scoped identity/session context.
-
#user_id_method ⇒ Symbol?
Method name to call on the user object to get distinct_id.
Instance Method Summary collapse
-
#default_excluded_exceptions ⇒ Array<String>
Default exceptions that Rails apps typically don’t want to track.
- #initialize ⇒ PostHog::Rails::Configuration constructor
-
#should_capture_exception?(exception) ⇒ Boolean
Whether the exception should be captured.
Constructor Details
#initialize ⇒ PostHog::Rails::Configuration
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/posthog/rails/configuration.rb', line 63 def initialize @auto_capture_exceptions = false @report_rescued_exceptions = false @auto_instrument_active_job = false @excluded_exceptions = [] @use_tracing_headers = true @capture_user_context = true @current_user_method = :current_user @user_id_method = nil @logs_enabled = false @logs_forward_rails_logger = true @logs_level = nil @logs_max_records_per_minute = DEFAULT_LOGS_MAX_RECORDS_PER_MINUTE @logs_before_send = nil end |
Instance Attribute Details
#auto_capture_exceptions ⇒ Boolean
Returns Whether to automatically capture exceptions from Rails. Defaults to false.
14 15 16 |
# File 'lib/posthog/rails/configuration.rb', line 14 def auto_capture_exceptions @auto_capture_exceptions end |
#auto_instrument_active_job ⇒ Boolean
Returns Whether to automatically instrument ActiveJob. Defaults to false.
20 21 22 |
# File 'lib/posthog/rails/configuration.rb', line 20 def auto_instrument_active_job @auto_instrument_active_job end |
#capture_user_context ⇒ Boolean
Returns Whether to capture the current user context in exceptions. Defaults to true.
30 31 32 |
# File 'lib/posthog/rails/configuration.rb', line 30 def capture_user_context @capture_user_context end |
#current_user_method ⇒ Symbol
Returns Method name to call on controller to get the current user. Defaults to :current_user.
33 34 35 |
# File 'lib/posthog/rails/configuration.rb', line 33 def current_user_method @current_user_method end |
#excluded_exceptions ⇒ Array<String>
Returns Exception class names to ignore in addition to the defaults.
23 24 25 |
# File 'lib/posthog/rails/configuration.rb', line 23 def excluded_exceptions @excluded_exceptions end |
#logs_before_send ⇒ Proc?
Callback invoked with each log record hash (:timestamp, :severity, :body, :attributes — where :severity is a symbol such as :warn) before it is sent to PostHog Logs. Return a (possibly modified) hash to send, or nil to drop the record — useful for scrubbing PII. If the callback raises, the record is dropped. Defaults to nil.
60 61 62 |
# File 'lib/posthog/rails/configuration.rb', line 60 def logs_before_send @logs_before_send end |
#logs_enabled ⇒ Boolean
Returns Master switch for forwarding logs to PostHog Logs over OTLP. Defaults to false.
40 41 42 |
# File 'lib/posthog/rails/configuration.rb', line 40 def logs_enabled @logs_enabled end |
#logs_forward_rails_logger ⇒ Boolean
Returns Whether to broadcast Rails.logger output into the PostHog Logs sink. Defaults to true (only takes effect when #logs_enabled is true).
44 45 46 |
# File 'lib/posthog/rails/configuration.rb', line 44 def logs_forward_rails_logger @logs_forward_rails_logger end |
#logs_level ⇒ Integer, ...
Returns Minimum severity to forward to PostHog Logs. When nil, inherits the current Rails.logger level. Accepts a Logger severity constant (e.g. Logger::INFO) or symbol (:info).
48 49 50 |
# File 'lib/posthog/rails/configuration.rb', line 48 def logs_level @logs_level end |
#logs_max_records_per_minute ⇒ Integer, ...
Returns Maximum log records forwarded to PostHog Logs per minute, protecting the ingestion quota from runaway log volume. Defaults to 6000. Numeric strings (e.g. from ENV) are coerced. Set to nil, 0, or a negative value to disable the cap; an unparseable value falls back to the default with a warning.
54 55 56 |
# File 'lib/posthog/rails/configuration.rb', line 54 def logs_max_records_per_minute @logs_max_records_per_minute end |
#report_rescued_exceptions ⇒ Boolean
Returns Whether to capture exceptions that Rails rescues (e.g., with rescue_from). Defaults to false.
17 18 19 |
# File 'lib/posthog/rails/configuration.rb', line 17 def report_rescued_exceptions @report_rescued_exceptions end |
#use_tracing_headers ⇒ Boolean
Returns Whether to use PostHog tracing headers for request-scoped identity/session context. Defaults to true.
27 28 29 |
# File 'lib/posthog/rails/configuration.rb', line 27 def use_tracing_headers @use_tracing_headers end |
#user_id_method ⇒ Symbol?
Returns Method name to call on the user object to get distinct_id. When nil, tries: posthog_distinct_id, distinct_id, id, pk, uuid in order.
37 38 39 |
# File 'lib/posthog/rails/configuration.rb', line 37 def user_id_method @user_id_method end |
Instance Method Details
#default_excluded_exceptions ⇒ Array<String>
Default exceptions that Rails apps typically don’t want to track.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/posthog/rails/configuration.rb', line 82 def default_excluded_exceptions [ 'AbstractController::ActionNotFound', 'ActionController::BadRequest', 'ActionController::InvalidAuthenticityToken', 'ActionController::InvalidCrossOriginRequest', 'ActionController::MethodNotAllowed', 'ActionController::NotImplemented', 'ActionController::ParameterMissing', 'ActionController::RoutingError', 'ActionController::UnknownFormat', 'ActionController::UnknownHttpMethod', 'ActionDispatch::Http::MimeNegotiation::InvalidType', 'ActionDispatch::Http::Parameters::ParseError', 'ActiveRecord::RecordNotFound', 'ActiveRecord::RecordNotUnique' ] end |
#should_capture_exception?(exception) ⇒ Boolean
Returns Whether the exception should be captured.
103 104 105 106 |
# File 'lib/posthog/rails/configuration.rb', line 103 def should_capture_exception?(exception) exception_name = exception.class.name !all_excluded_exceptions.include?(exception_name) end |