Skip to content

Commit

Permalink
Replace Instant with SystemTime to follow opentelemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
ileixe committed Feb 1, 2023
1 parent d97b8ea commit a7f5b28
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tracing-chrometrace"
version = "0.1.18"
version = "0.1.19"
edition = "2018"

authors = ["Youseok Yang <[email protected]>"]
Expand Down
19 changes: 9 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
//! tracing_subscriber::registry().with(writer).init();
//! ```
#![feature(derive_default_enum)]
#![feature(thread_id_value)]

use std::borrow::Cow;
use std::marker::PhantomData;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use std::{collections::HashMap, io, time::Instant};
use std::{collections::HashMap, io, time::SystemTime};

use crossbeam_queue::ArrayQueue;
use derivative::Derivative;
Expand Down Expand Up @@ -84,11 +83,11 @@ pub enum EventType {
#[builder(derive(Debug))]
pub struct ChromeEvent {
#[builder(setter(custom))]
#[serde(default = "Instant::now")]
#[serde(default = "SystemTime::now")]
#[serde(skip)]
#[allow(unused)]
#[derivative(PartialEq = "ignore")]
start: Instant,
start: SystemTime,
#[builder(default)]
#[builder(setter(into))]
pub name: Cow<'static, str>,
Expand All @@ -98,7 +97,7 @@ pub struct ChromeEvent {
#[builder(default)]
pub ph: EventType,
#[builder(
default = "Instant::now().duration_since(self.start.unwrap()).as_nanos() as f64 / 1000.0"
default = "SystemTime::now().duration_since(self.start.unwrap()).unwrap().as_nanos() as f64 / 1000.0"
)]
pub ts: f64,
#[builder(default)]
Expand All @@ -121,7 +120,7 @@ pub struct ChromeEvent {
}

impl ChromeEvent {
pub fn builder(start: Instant) -> ChromeEventBuilder {
pub fn builder(start: SystemTime) -> ChromeEventBuilder {
ChromeEventBuilder {
start: Some(start),
..ChromeEventBuilder::create_empty()
Expand All @@ -131,7 +130,7 @@ impl ChromeEvent {

#[derive(Debug)]
pub struct ChromeLayer<S, W = fn() -> std::io::Stdout> {
pub start: Instant,
pub start: SystemTime,
make_writer: W,
events: Arc<Mutex<ArrayQueue<String>>>,
_inner: PhantomData<S>,
Expand Down Expand Up @@ -251,7 +250,7 @@ where
let (make_writer, guard) = ChromeWriter::new(make_writer, events.clone());
(
ChromeLayer {
start: Instant::now(),
start: SystemTime::now(),
make_writer,
events,
_inner: PhantomData,
Expand Down Expand Up @@ -285,7 +284,7 @@ struct ChromeEventVisitor {

impl tracing_subscriber::field::Visit for ChromeEventVisitor {
fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn std::fmt::Debug) {
let value = format!("{:?}", value).trim_matches('"').to_string();
let value = format!("{value:?}").trim_matches('"').to_string();
let name = field.name();

match name {
Expand Down Expand Up @@ -440,7 +439,7 @@ mod tests {

#[test]
fn test_serde() {
let event = ChromeEvent::builder(Instant::now())
let event = ChromeEvent::builder(SystemTime::now())
.arg(("a".to_string(), "a".to_string()))
.ts(1.0)
.build()
Expand Down

0 comments on commit a7f5b28

Please sign in to comment.