Class: PostHog::Rails::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/posthog/rails/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePostHog::Rails::Configuration



33
34
35
36
37
38
39
40
41
42
# File 'lib/posthog/rails/configuration.rb', line 33

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
end

Instance Attribute Details

#auto_capture_exceptionsBoolean

Returns Whether to automatically capture exceptions from Rails. Defaults to false.

Returns:

  • (Boolean)

    Whether to automatically capture exceptions from Rails. Defaults to false.



7
8
9
# File 'lib/posthog/rails/configuration.rb', line 7

def auto_capture_exceptions
  @auto_capture_exceptions
end

#auto_instrument_active_jobBoolean

Returns Whether to automatically instrument ActiveJob. Defaults to false.

Returns:

  • (Boolean)

    Whether to automatically instrument ActiveJob. Defaults to false.



13
14
15
# File 'lib/posthog/rails/configuration.rb', line 13

def auto_instrument_active_job
  @auto_instrument_active_job
end

#capture_user_contextBoolean

Returns Whether to capture the current user context in exceptions. Defaults to true.

Returns:

  • (Boolean)

    Whether to capture the current user context in exceptions. Defaults to true.



23
24
25
# File 'lib/posthog/rails/configuration.rb', line 23

def capture_user_context
  @capture_user_context
end

#current_user_methodSymbol

Returns Method name to call on controller to get the current user. Defaults to :current_user.

Returns:

  • (Symbol)

    Method name to call on controller to get the current user. Defaults to :current_user.



26
27
28
# File 'lib/posthog/rails/configuration.rb', line 26

def current_user_method
  @current_user_method
end

#excluded_exceptionsArray<String>

Returns Exception class names to ignore in addition to the defaults.

Returns:

  • (Array<String>)

    Exception class names to ignore in addition to the defaults.



16
17
18
# File 'lib/posthog/rails/configuration.rb', line 16

def excluded_exceptions
  @excluded_exceptions
end

#report_rescued_exceptionsBoolean

Returns Whether to capture exceptions that Rails rescues (e.g., with rescue_from). Defaults to false.

Returns:

  • (Boolean)

    Whether to capture exceptions that Rails rescues (e.g., with rescue_from). Defaults to false.



10
11
12
# File 'lib/posthog/rails/configuration.rb', line 10

def report_rescued_exceptions
  @report_rescued_exceptions
end

#use_tracing_headersBoolean

Returns Whether to use PostHog tracing headers for request-scoped identity/session context. Defaults to true.

Returns:

  • (Boolean)

    Whether to use PostHog tracing headers for request-scoped identity/session context. Defaults to true.



20
21
22
# File 'lib/posthog/rails/configuration.rb', line 20

def use_tracing_headers
  @use_tracing_headers
end

#user_id_methodSymbol?

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.

Returns:

  • (Symbol, nil)

    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.



30
31
32
# File 'lib/posthog/rails/configuration.rb', line 30

def user_id_method
  @user_id_method
end

Instance Method Details

#default_excluded_exceptionsArray<String>

Default exceptions that Rails apps typically don’t want to track.

Returns:

  • (Array<String>)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/posthog/rails/configuration.rb', line 47

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::Parameters::ParseError',
    'ActiveRecord::RecordNotFound',
    'ActiveRecord::RecordNotUnique'
  ]
end

#should_capture_exception?(exception) ⇒ Boolean

Returns Whether the exception should be captured.

Parameters:

  • exception (Exception)

    The exception to check.

Returns:

  • (Boolean)

    Whether the exception should be captured.



67
68
69
70
# File 'lib/posthog/rails/configuration.rb', line 67

def should_capture_exception?(exception)
  exception_name = exception.class.name
  !all_excluded_exceptions.include?(exception_name)
end