Class: FlowChat::Session::Middleware

Inherits:
Object
  • Object
show all
Includes:
Instrumentation
Defined in:
lib/flow_chat/session/middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Instrumentation

#instrument, instrument

Constructor Details

#initialize(app, session_options) ⇒ Middleware

Returns a new instance of Middleware.



8
9
10
11
12
# File 'lib/flow_chat/session/middleware.rb', line 8

def initialize(app, session_options)
  @app = app
  @session_options = session_options
  FlowChat.logger.debug { "Session::Middleware: Initialized session middleware" }
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/flow_chat/session/middleware.rb', line 6

def context
  @context
end

Instance Method Details

#call(context) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/flow_chat/session/middleware.rb', line 14

def call(context)
  @context = context
  session_id = session_id(context)
  FlowChat.logger.debug { "Session::Middleware: Generated session ID: #{session_id}" }

  context["session.id"] = session_id
  context.session = context["session.store"].new(context)

  # Use instrumentation instead of direct logging for session creation
  store_type = context["session.store"].name || "$Anonymous"
  instrument(Events::SESSION_CREATED, {
    session_id: session_id,
    store_type: store_type,
    gateway: context["request.gateway"]
  })

  FlowChat.logger.debug { "Session::Middleware: Session store: #{context["session.store"].class.name}" }

  result = @app.call(context)

  FlowChat.logger.debug { "Session::Middleware: Session processing completed for #{session_id}" }
  result
rescue => error
  FlowChat.logger.error { "Session::Middleware: Error in session processing for #{session_id}: #{error.class.name}: #{error.message}" }
  raise
end