Skip to main content

Session Tracking

Sessions let you group logs from the same user session, making it easy to follow a user’s journey through your application.

Automatic Session Tracking

In Rails, Recall automatically captures the session ID from session.id:
# All logs in a request automatically include session_id
BrainzLab::Recall.info("Page viewed", page: "/dashboard")
# => { session: "sess_abc123", ... }

Manual Session ID

Set a custom session identifier:
BrainzLab.set_session("custom_session_id")
This is useful for:
  • API requests without Rails sessions
  • Mobile app sessions
  • Custom session management

Query by Session

Find all logs for a session:
session:sess_abc123
Or in the dashboard, click on any log to see the full session.

Session Timeline

The dashboard shows a timeline view of session events:
10:00:05  info   User logged in
10:00:12  info   Dashboard viewed
10:00:45  info   Settings updated
10:01:02  error  Payment failed
10:01:15  info   Payment retry succeeded

Correlation IDs

For distributed systems, use correlation IDs alongside sessions:
BrainzLab.set_context(
  session_id: session.id,
  correlation_id: request.headers["X-Correlation-ID"]
)
Query across services:
data.correlation_id:corr_xyz789

Session Analytics

Get session statistics:
since:24h | stats by:session
This shows:
  • Log count per session
  • Error rate per session
  • Active sessions over time

Session Replay

With sufficient logging, you can replay what happened in a session:
# Log key user actions
BrainzLab::Recall.info("Navigation",
  action: "page_view",
  path: request.path,
  referrer: request.referrer
)

BrainzLab::Recall.info("Interaction",
  action: "button_click",
  element: "checkout_button",
  page: "/cart"
)

Best Practices

Log Session Start/End

# On login
BrainzLab::Recall.info("Session started",
  user_id: user.id,
  login_method: "password"
)

# On logout
BrainzLab::Recall.info("Session ended",
  duration_minutes: session_duration
)

Include User Journey Context

BrainzLab::Recall.info("Checkout started",
  step: 1,
  cart_value: cart.total,
  item_count: cart.items.count
)

BrainzLab::Recall.info("Checkout step completed",
  step: 2,
  step_name: "shipping_address"
)

Track Funnel Steps

BrainzLab::Recall.info("Funnel step",
  funnel: "onboarding",
  step: 3,
  step_name: "connect_github",
  completed: true
)