pub struct SessionManager { /* private fields */ }Expand description
In-memory session state.
All persistence is handled by free functions in this module.
All mutation happens on the Glean dispatcher thread — no internal synchronization needed.
Fields are pub(crate) to prevent mutation from outside the crate while still
allowing core/mod.rs to drive the session lifecycle directly.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(
mode: SessionMode,
sample_rate: f64,
inactivity_timeout: Duration,
) -> Self
pub fn new( mode: SessionMode, sample_rate: f64, inactivity_timeout: Duration, ) -> Self
Creates a new SessionManager.
sample_rate is clamped to [0.0, 1.0]; values outside that range are
silently brought to the nearest bound. This matches the behaviour of the
remote-settings override path so the two paths are always consistent.
Sourcepub fn is_sampled_in(&self) -> bool
pub fn is_sampled_in(&self) -> bool
Returns whether the current session is sampled in.
Returns true when no session is active (between sessions),
so telemetry recorded outside of a session is never suppressed.
Sourcepub fn session_id(&self) -> Option<Uuid>
pub fn session_id(&self) -> Option<Uuid>
Returns the current session’s UUID, if a session is active.
Sourcepub fn sampled_in(&self) -> bool
pub fn sampled_in(&self) -> bool
Returns whether the current session is sampled in (direct field access).
Differs from is_sampled_in in that it returns the raw field value
without the “inactive → true” override, useful for asserting the exact
sampling decision made at session start.
Sourcepub fn session_start_time(&self) -> Option<DateTime<FixedOffset>>
pub fn session_start_time(&self) -> Option<DateTime<FixedOffset>>
Returns the wall-clock timestamp recorded when the current session started.
Sourcepub fn current_metadata(&self) -> Option<SessionMetadata>
pub fn current_metadata(&self) -> Option<SessionMetadata>
Returns the current session’s metadata without incrementing event_seq.
Sourcepub fn compute_event_context(&self) -> EventSessionContext
pub fn compute_event_context(&self) -> EventSessionContext
Computes the session context (metadata attachment decision) for a single event.
Precondition: the caller must have already verified via
MetricType::should_record() that the event should be recorded. That
check handles sampling suppression for all metric types; this function
is concerned only with what context to attach, not whether to record.
Returns OutOfSession when no session is active (between sessions), or
InSession(meta) when an active session is present.
event_seq is incremented only for InSession results so that
between-session events do not consume sequence numbers.
Sourcepub fn current_metadata_with_next_seq(&self) -> Option<SessionMetadata>
pub fn current_metadata_with_next_seq(&self) -> Option<SessionMetadata>
Returns the current session’s metadata with an atomically incremented event_seq.
Called from EventMetric::record_sync which only holds &Glean.
Sourcepub fn reset_state(&mut self)
pub fn reset_state(&mut self)
Used to reset the in-memory state of the session manager when a session ends.