Skip to main content

Session Instrumentation

Generates: Events (Log Records)

Manages session lifecycle and stamps every span and log with a session.id for session-scoped analysis in the Pulse dashboard.

How It Works

On SDK initialization, a new session is created with a unique 32-character hex ID. The session ID is injected into every span and log record by the SDK's processor chain. Sessions expire based on two configurable limits:

  • Max lifetime: The session expires after a fixed duration from its start time
  • Background inactivity timeout: The session expires if the app remains backgrounded for longer than this period

When a session expires, a new one is automatically created on the next foreground event.

Configuration

Sessions are enabled by default.

Pulse.shared.initialize(
endpointBaseUrl: "https://your-backend.com",
apiKey: "your-api-key",
instrumentations: { config in
config.sessions { sessions in
sessions.enabled(true)
sessions.maxLifetime(4 * 60 * 60) // 4 hours (default)
sessions.backgroundInactivityTimeout(15 * 60) // 15 minutes (default)
}
}
)

Configuration Options

OptionTypeDefaultDescription
enabled(Bool)BooltrueEnable/disable session tracking
maxLifetime(TimeInterval?)TimeInterval?14400 (4 h)Fixed session duration from start. Pass nil to disable the hard cap
backgroundInactivityTimeout(TimeInterval?)TimeInterval?900 (15 min)Time app can stay backgrounded before session expires. Pass nil to disable
warning

Change these defaults with care. Session lifetime directly defines how Pulse groups telemetry into sessions — modifying it will change what counts as a "session" across all analysis, dashboards, and alerts. It also affects Session Replay: a session boundary triggers a new replay recording, so tuning the timeout too aggressively will fragment replays or cause premature cutoffs.

What Gets Tracked

The session instrumentation emits two log events:

Session Start

Emitted when a new session begins.

AttributeDescriptionExample
pulse.type"session.start"
session.idNew session identifier"f40364c92b85ec0c19c35a65be42b97f"
session.start_timeSession start epoch ms1732694400000
session.previous_idPrior session ID"a1b2c3..." (if any)

Session End

Emitted when a session expires.

AttributeDescriptionExample
pulse.type"session.end"
session.idEnding session identifier"f40364c92b85ec0c19c35a65be42b97f"
session.start_timeWhen session started1732694400000
session.end_timeWhen session ended1732708800000
session.durationDuration in ms14400000

Disabling Sessions

config.sessions { $0.enabled(false) }

When disabled, no session.id is attached to spans or logs, and session start/end events are not emitted.