Class: PostHog::Rails::CaptureExceptions Private

Inherits:
Object
  • Object
show all
Includes:
ParameterFilter
Defined in:
lib/posthog/rails/capture_exceptions.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Middleware that captures exceptions and sends them to PostHog.

Constant Summary

Constants included from ParameterFilter

ParameterFilter::EMPTY_HASH, ParameterFilter::MAX_DEPTH, ParameterFilter::MAX_STRING_LENGTH

Instance Method Summary collapse

Methods included from ParameterFilter

backend, #filter_sensitive_params, #safe_serialize

Constructor Details

#initialize(app) ⇒ CaptureExceptions

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CaptureExceptions.

Parameters:

  • app (#call)

    Rack application.



14
15
16
# File 'lib/posthog/rails/capture_exceptions.rb', line 14

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Rack response.

Parameters:

  • env (Hash)

    Rack environment.

Returns:

  • (Array)

    Rack response.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/posthog/rails/capture_exceptions.rb', line 20

def call(env)
  # Signal that we're in a web request context
  # ErrorSubscriber will skip capture for web requests to avoid duplicates
  PostHog::Rails.enter_web_request

  response = @app.call(env)
  env['posthog.response_status_code'] = response_status(response)

  # Check if there was an exception that Rails handled
  exception = collect_exception(env)

  capture_exception(exception, env) if exception && should_capture?(exception)

  response
rescue StandardError => e
  # Capture unhandled exceptions
  capture_exception(e, env) if should_capture?(e)
  raise
ensure
  PostHog::Rails.exit_web_request
end