Skip to content

Commit 3cc33d7

Browse files
committed
fix: use offset for start time
1 parent 010f299 commit 3cc33d7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Fix
10+
11+
- Use offset for start time
912

1013
## [0.3.3]
1114

src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use chrono::{DateTime, Utc};
1818
use futures::lock::Mutex;
1919
use protobuf::well_known_types::Timestamp;
2020
use protobuf::RepeatedField;
21+
use std::convert::TryFrom;
2122

2223
use async_graphql::extensions::{
2324
Extension, ExtensionContext, ExtensionFactory, NextExecute, NextParseQuery, NextResolve,
@@ -404,7 +405,7 @@ impl Extension for ApolloTracingExtension {
404405
let field_name = info.path_node.field_name().to_string();
405406
let parent_type = info.parent_type.to_string();
406407
let return_type = info.return_type.to_string();
407-
let start_time = Utc::now();
408+
let start_time = Utc::now() - self.inner.lock().await.start_time;
408409
let path_node = info.path_node;
409410

410411
let node: Trace_Node = Trace_Node {
@@ -417,7 +418,13 @@ impl Extension for ApolloTracingExtension {
417418
Some(Trace_Node_oneof_id::index(index.try_into().unwrap_or(0)))
418419
}
419420
},
420-
start_time: start_time.timestamp_nanos().try_into().unwrap(),
421+
start_time: match start_time
422+
.num_nanoseconds()
423+
.and_then(|x| u64::try_from(x).ok())
424+
{
425+
Some(duration) => duration,
426+
None => Utc::now().timestamp_nanos().try_into().unwrap(),
427+
},
421428
parent_type: parent_type.to_string(),
422429
original_field_name: field_name,
423430
field_type: return_type,

0 commit comments

Comments
 (0)