Module: PostHog::Rails

Defined in:
lib/posthog/rails.rb,
lib/posthog/rails/railtie.rb,
lib/posthog/rails/active_job.rb,
lib/posthog/rails/logs/setup.rb,
lib/posthog/rails/configuration.rb,
lib/posthog/rails/logs/appender.rb,
lib/posthog/rails/logs/severity.rb,
lib/posthog/rails/request_context.rb,
lib/posthog/rails/tracing_headers.rb,
lib/posthog/rails/error_subscriber.rb,
lib/posthog/rails/parameter_filter.rb,
lib/posthog/rails/request_metadata.rb,
lib/posthog/rails/logs/rate_limiter.rb,
lib/posthog/rails/capture_exceptions.rb,
lib/posthog/rails/rescued_exception_interceptor.rb

Defined Under Namespace

Modules: ActiveJobExtensions, Logs, ParameterFilter Classes: CaptureExceptions, Configuration, ErrorSubscriber, InitConfig, Railtie, RequestContext, RescuedExceptionInterceptor

Constant Summary collapse

VERSION =
PostHog::VERSION
IN_WEB_REQUEST_KEY =

Thread-local key for tracking web request context

:posthog_in_web_request

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configPostHog::Rails::Configuration

Returns Rails integration configuration.

Returns:



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

def config
  @config ||= Configuration.new
end

Class Method Details

.configure {|config| ... } ⇒ void

This method returns an undefined value.

Configure Rails integration options.

Yield Parameters:



37
38
39
# File 'lib/posthog/rails.rb', line 37

def configure
  yield config if block_given?
end

.enter_web_requestvoid

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.

This method returns an undefined value.

Mark that we’re in a web request context CaptureExceptions middleware will handle exception capture



45
46
47
# File 'lib/posthog/rails.rb', line 45

def enter_web_request
  Thread.current[IN_WEB_REQUEST_KEY] = true
end

.exit_web_requestvoid

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.

This method returns an undefined value.

Clear web request context (called at end of request)



52
53
54
# File 'lib/posthog/rails.rb', line 52

def exit_web_request
  Thread.current[IN_WEB_REQUEST_KEY] = false
end

.in_web_request?Boolean

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.

Check if we’re currently in a web request context Used by ErrorSubscriber to avoid duplicate captures

Returns:

  • (Boolean)


60
61
62
# File 'lib/posthog/rails.rb', line 60

def in_web_request?
  Thread.current[IN_WEB_REQUEST_KEY] == true
end