Skip to content

Commit

Permalink
Span link test
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-near committed Mar 25, 2024
1 parent 84f7c75 commit 8852884
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions neard/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use near_o11y::opentelemetry::root_span_for_chunk;
use near_o11y::tracing_subscriber::EnvFilter;
use near_o11y::{
default_subscriber, default_subscriber_with_opentelemetry, BuildEnvFilterError,
EnvFilterBuilder, OpenTelemetryLevel, Options,
EnvFilterBuilder, OpenTelemetryLevel, OpenTelemetrySpanExt, Options,
};
use near_ping::PingCommand;
use near_primitives::hash::CryptoHash;
Expand All @@ -30,6 +30,7 @@ use near_state_viewer::StateViewerSubCommand;
use near_store::db::RocksDB;
use near_store::Mode;
use near_undo_block::cli::UndoBlockCommand;
use opentelemetry::trace::TraceContextExt;
use serde_json::Value;
use std::fs::File;
use std::io::BufReader;
Expand Down Expand Up @@ -881,14 +882,30 @@ impl TraceTestCommand {
// QUESTION: Why do these trace spans not seem to do anything at all?
// It doesn't even print out on stderr. Even without this first line.
// let _ = root_span_for_chunk(CryptoHash::hash_bytes(b"test")).entered();
let _ = tracing::error_span!("test1").entered();
let _ = tracing::error_span!("test2").entered();
let _ = tracing::error_span!("test3").entered();
let _ = tracing::error_span!("test4").entered();
let _ = tracing::error_span!("test5").entered();
tracing::error!("test info log");
std::thread::sleep(std::time::Duration::from_secs(1));
// let _ = tracing::error_span!("test1").entered();
// let _ = tracing::error_span!("test2").entered();
// let _ = tracing::error_span!("test3").entered();
// let _ = tracing::error_span!("test4").entered();
// let _ = tracing::error_span!("test5").entered();
// tracing::error!("test info log");
// std::thread::sleep(std::time::Duration::from_secs(1));

std::thread::spawn(|| {
let root1 = tracing::info_span!("root1").entered();
let span1 = tracing::info_span!("span1");
let _ = span1.enter();
drop(root1);

let root2 = tracing::info_span!("root2").entered();
let span2 = tracing::info_span!("span2");
span2.add_link(span1.context().span().span_context().clone());
let _ = span2.entered();
drop(root2);
})
.join()
.unwrap();
}

// Wait for something to upload the traces?
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
});
Expand Down

0 comments on commit 8852884

Please sign in to comment.