pub struct ClockDriftProcessor { /* private fields */ }
Expand description
Corrects clock drift based on the sender’s and receivers timestamps.
Clock drift correction applies to all timestamps in the event protocol. This includes especially the event’s timestamp, breadcrumbs and spans.
There is a minimum clock drift of 55 minutes to compensate for network latency and small clock drift on the sender’s machine, but allow to detect timezone differences. For differences lower than that, no correction is performed.
Clock drift is corrected in both ways:
-
The drift is added to timestamps if the received time is after the send time. This indicates that the sender’s clock was lagging behind. For instance, if an event was received with yesterday’s timestamp, one day is added to all timestamps.
-
The drift is subtracted from timestamps if the received time is before the send time. This indicates that the sender’s clock was running ahead. For instance, if an event was received with tomorrow’s timestamp, one day is subtracted from all timestamps.
Implementations§
source§impl ClockDriftProcessor
impl ClockDriftProcessor
sourcepub fn new(sent_at: Option<DateTime<Utc>>, received_at: DateTime<Utc>) -> Self
pub fn new(sent_at: Option<DateTime<Utc>>, received_at: DateTime<Utc>) -> Self
Creates a new ClockDriftProcessor
.
If no sent_at
timestamp is provided, then clock drift correction is disabled. The drift is
calculated from the signed difference between the receiver’s and the sender’s timestamp.
sourcepub fn at_least(self, lower_bound: Duration) -> Self
pub fn at_least(self, lower_bound: Duration) -> Self
Limits clock drift correction to a minimum duration.
If the detected clock drift is lower than the given duration, no correction is performed and
is_drifted
returns false
. By default, there is no lower bound and every drift is
corrected.
sourcepub fn error_kind(self, kind: ErrorKind) -> Self
pub fn error_kind(self, kind: ErrorKind) -> Self
Use the given error kind for the attached eventerror instead of the default
ErrorKind::ClockDrift
.
sourcepub fn is_drifted(&self) -> bool
pub fn is_drifted(&self) -> bool
Returns true
if the clocks are significantly drifted.
sourcepub fn process_timestamp(&self, timestamp: &mut UnixTimestamp)
pub fn process_timestamp(&self, timestamp: &mut UnixTimestamp)
Processes the given UnixTimestamp
by applying clock drift correction.
sourcepub fn process_datetime(&self, datetime: &mut DateTime<Utc>)
pub fn process_datetime(&self, datetime: &mut DateTime<Utc>)
Processes the given DateTime
.