pub struct SessionId(/* private fields */);Expand description
A session’s identity.
A u64 behind a newtype rather than a string: it is compared constantly,
and Copy is what lets it sit inside every event without a borrow.
Where the value comes from is IdSource’s
business, not this type’s — a counter is fine for one process, and
adapters::secondary::id_source::RandomIds exists for a deployment that
needs them unguessable. Deliberately not an intra-doc link: that module is
behind the random-ids feature, and a link to it breaks every lean build’s
documentation for a type that is compiled in all of them.
§Redaction
Debug prints SessionId(…) and never the value. Debug is
what a panic, an assert_eq! and a dbg! expand to, so leaving it derived
made “we never log session ids” a convention rather than a property of the
type. RequestId keeps a
four-character prefix so two ids in one line can be told apart; this cannot,
because there is nothing here to keep — the whole value is a counter, so
every digit of it is either the value itself or a leading zero.
McpSessionId derives its
Debug from this one, so it inherits the redaction rather than needing an
impl of its own.
§Why Display is not redacted
This is load-bearing, not an oversight.
IdempotencyKey::for_request
composes "{session}/{id}", so a redacted Display would collapse every
session onto one key and let a result recorded for one session answer
another’s request. Display is the identity and serialisation API here, not
a logging one, and the redaction belongs at Debug because that is the
path a value escapes through by accident.