Skip to content

Commit ad3a549

Browse files
authored
[chore] Use elapsed() if possible when calculating durations (#750)
1 parent 2fa4a79 commit ad3a549

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

src/stats_processor.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use std::sync::Arc;
5-
use std::time::{SystemTime, UNIX_EPOCH};
5+
use std::time::UNIX_EPOCH;
66

77
use async_trait::async_trait;
88
use hyper::{http, Body, Request, Response, StatusCode};
@@ -63,11 +63,7 @@ impl StatsProcessor for ServerlessStatsProcessor {
6363
};
6464

6565
if !stats.stats.is_empty() {
66-
let start = SystemTime::now();
67-
let timestamp = start
68-
.duration_since(UNIX_EPOCH)
69-
.unwrap_or_default()
70-
.as_nanos();
66+
let timestamp = UNIX_EPOCH.elapsed().unwrap_or_default().as_nanos();
7167
stats.stats[0].start = timestamp as u64;
7268
}
7369

src/trace_processor.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ impl TraceProcessor for ServerlessTraceProcessor {
122122
mod tests {
123123
use datadog_trace_obfuscation::obfuscation_config::ObfuscationConfig;
124124
use hyper::Request;
125-
use std::{
126-
collections::HashMap,
127-
sync::Arc,
128-
time::{SystemTime, UNIX_EPOCH},
129-
};
125+
use std::{collections::HashMap, sync::Arc, time::UNIX_EPOCH};
130126
use tokio::sync::mpsc::{self, Receiver, Sender};
131127

132128
use crate::{
@@ -142,10 +138,7 @@ mod tests {
142138
use ddcommon::Endpoint;
143139

144140
fn get_current_timestamp_nanos() -> i64 {
145-
SystemTime::now()
146-
.duration_since(UNIX_EPOCH)
147-
.unwrap()
148-
.as_nanos() as i64
141+
UNIX_EPOCH.elapsed().unwrap().as_nanos() as i64
149142
}
150143

151144
fn create_test_config() -> Config {

0 commit comments

Comments
 (0)