Skip to main content

SessionManager

Struct SessionManager 

Source
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

Source

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.

Source

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.

Source

pub fn is_active(&self) -> bool

Returns whether a session is currently active.

Source

pub fn session_id(&self) -> Option<Uuid>

Returns the current session’s UUID, if a session is active.

Source

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.

Source

pub fn session_start_time(&self) -> Option<DateTime<FixedOffset>>

Returns the wall-clock timestamp recorded when the current session started.

Source

pub fn current_metadata(&self) -> Option<SessionMetadata>

Returns the current session’s metadata without incrementing event_seq.

Source

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.

Source

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.

Source

pub fn reset_state(&mut self)

Used to reset the in-memory state of the session manager when a session ends.

Trait Implementations§

Source§

impl Debug for SessionManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
Source§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.