Class: PostHog::Rails::RequestContext Private

Inherits:
Object
  • Object
show all
Defined in:
lib/posthog/rails/request_context.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.

Rack middleware that creates a request-local PostHog context from tracing headers.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestContext

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 RequestContext.

Parameters:

  • app (#call)

    Rack application.



14
15
16
# File 'lib/posthog/rails/request_context.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
# File 'lib/posthog/rails/request_context.rb', line 20

def call(env)
  request = build_request(env)

  Internal::Context.with_context(context_data(request), fresh: true) do
    @app.call(env)
  end
end