Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use opentelemetry:time::now instead of systemtime #2593

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions opentelemetry-prometheus/examples/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use opentelemetry_sdk::metrics::SdkMeterProvider;
use prometheus::{Encoder, Registry, TextEncoder};
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::SystemTime;
use opentelemetry::time::now;
use tokio::net::TcpListener;

static HANDLER_ALL: Lazy<[KeyValue; 1]> = Lazy::new(|| [KeyValue::new("handler", "all")]);
Expand All @@ -25,7 +25,7 @@ async fn serve_req(
state: Arc<AppState>,
) -> Result<Response<Full<Bytes>>, hyper::Error> {
println!("Receiving request at path {}", req.uri());
let request_start = SystemTime::now();
let request_start = now();

state.http_counter.add(1, HANDLER_ALL.as_ref());

Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/benches/batch_span_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use opentelemetry_sdk::trace::{
BatchConfigBuilder, BatchSpanProcessor, SpanEvents, SpanLinks, SpanProcessor,
};
use std::sync::Arc;
use std::time::SystemTime;
use opentelemetry::time::now;
use tokio::runtime::Runtime;

fn get_span_data() -> Vec<SpanData> {
Expand All @@ -24,8 +24,8 @@ fn get_span_data() -> Vec<SpanData> {
parent_span_id: SpanId::from_u64(12),
span_kind: SpanKind::Client,
name: Default::default(),
start_time: SystemTime::now(),
end_time: SystemTime::now(),
start_time: now(),
end_time: now(),
attributes: Vec::new(),
dropped_attributes_count: 0,
events: SpanEvents::default(),
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/benches/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RAM: 64.0 GB
*/

use std::collections::HashMap;
use std::time::SystemTime;
use opentelemetry::time::now;

use criterion::{criterion_group, criterion_main, Criterion};

Expand Down Expand Up @@ -111,7 +111,7 @@ fn logging_comparable_to_appender(c: &mut Criterion) {
c.bench_function("Logging_Comparable_To_Appender", |b| {
b.iter(|| {
let mut log_record = logger.create_log_record();
let now = SystemTime::now();
let now = now();
log_record.set_observed_timestamp(now);
log_record.set_target("my-target".to_string());
log_record.set_event_name("CheckoutFailed");
Expand Down Expand Up @@ -253,7 +253,7 @@ fn criterion_benchmark(c: &mut Criterion) {
logger.emit(log_record);
});

let now = SystemTime::now();
let now = now();
log_benchmark_group(c, "full-log", |logger| {
let mut log_record = logger.create_log_record();
log_record.set_body("full log".into());
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/benches/log_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

use std::sync::Mutex;
use std::time::SystemTime;
use opentelemetry::time::now;

use async_trait::async_trait;
use criterion::{criterion_group, criterion_main, Criterion};
Expand Down Expand Up @@ -126,7 +126,7 @@ fn exporter_with_future(c: &mut Criterion) {
c.bench_function("LogExporterWithFuture", |b| {
b.iter(|| {
let mut log_record = logger.create_log_record();
let now = SystemTime::now();
let now = now();
log_record.set_observed_timestamp(now);
log_record.set_target("my-target".to_string());
log_record.set_event_name("CheckoutFailed");
Expand All @@ -152,7 +152,7 @@ fn exporter_without_future(c: &mut Criterion) {
c.bench_function("LogExporterWithoutFuture", |b| {
b.iter(|| {
let mut log_record = logger.create_log_record();
let now = SystemTime::now();
let now = now();
log_record.set_observed_timestamp(now);
log_record.set_target("my-target".to_string());
log_record.set_event_name("CheckoutFailed");
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/benches/log_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use std::{
sync::{Arc, Mutex},
thread::sleep,
time::SystemTime,
};
use opentelemetry::time::now;

use criterion::{criterion_group, criterion_main, Criterion};
use opentelemetry::{
Expand All @@ -29,7 +29,7 @@ use opentelemetry_sdk::logs::{LogProcessor, LogRecord, LogResult, Logger, Logger

fn create_log_record(logger: &Logger) -> LogRecord {
let mut log_record = logger.create_log_record();
let now = SystemTime::now();
let now = now();
log_record.set_observed_timestamp(now);
log_record.set_target("my-target".to_string());
log_record.set_event_name("CheckoutFailed");
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,15 @@ pub mod logs;
#[doc(hidden)]
#[cfg(any(feature = "metrics", feature = "trace", feature = "logs"))]
pub mod time {
use std::time::SystemTime;
use opentelemetry::time::now;

#[doc(hidden)]
#[cfg(any(
not(target_arch = "wasm32"),
all(target_arch = "wasm32", target_os = "wasi")
))]
pub fn now() -> SystemTime {
SystemTime::now()
now()
}

#[doc(hidden)]
Expand Down
Loading