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

test: add tracing to comms via --tracing-enabled #3238

Merged
merged 2 commits into from
Aug 27, 2021
Merged
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
137 changes: 120 additions & 17 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions applications/tari_base_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ strum = "^0.19"
strum_macros = "0.18.0"
thiserror = "^1.0.20"
tonic = "0.2"
tracing = "0.1.26"
tracing-opentelemetry = "0.15.0"
tracing-subscriber = "0.2.20"

# network tracing, rt-tokio for async batch export
opentelemetry = { version = "0.16", default-features = false, features = ["trace","rt-tokio"] }
opentelemetry-jaeger = { version="0.15", features=["rt-tokio"]}

[features]
avx2 = ["tari_core/avx2", "tari_crypto/avx2", "tari_p2p/avx2", "tari_wallet/avx2", "tari_comms/avx2", "tari_comms_dht/avx2"]
Expand Down
1 change: 1 addition & 0 deletions applications/tari_base_node/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub struct BaseNodeContext {
impl BaseNodeContext {
/// Starts the node container. This entails the base node state machine.
/// This call consumes the NodeContainer instance.
#[tracing::instrument(name = "base_node::run", skip(self))]
pub async fn run(self) {
info!(target: LOG_TARGET, "Tari base node has STARTED");

Expand Down
26 changes: 25 additions & 1 deletion applications/tari_base_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ mod utils;
use crate::command_handler::{CommandHandler, StatusOutput};
use futures::{future::Fuse, pin_mut, FutureExt};
use log::*;
use opentelemetry::{self, global, KeyValue};
use parser::Parser;
use rustyline::{config::OutputStreamType, error::ReadlineError, CompletionType, Config, EditMode, Editor};
use std::{
env,
net::SocketAddr,
process,
sync::Arc,
Expand All @@ -120,6 +122,7 @@ use tokio::{
time::{self, Delay},
};
use tonic::transport::Server;
use tracing_subscriber::{layer::SubscriberExt, Registry};

const LOG_TARGET: &str = "base_node::app";
/// Application entry point
Expand Down Expand Up @@ -148,12 +151,14 @@ fn main_inner() -> Result<(), ExitCodes> {
})?;

rt.block_on(run_node(node_config.into(), bootstrap))?;

// Shutdown and send any traces
global::shutdown_tracer_provider();
Ok(())
}

/// Sets up the base node and runs the cli_loop
async fn run_node(node_config: Arc<GlobalConfig>, bootstrap: ConfigBootstrap) -> Result<(), ExitCodes> {
enable_tracing_if_specified(&bootstrap);
// Load or create the Node identity
let node_identity = setup_node_identity(
&node_config.base_node_identity_file,
Expand Down Expand Up @@ -247,6 +252,25 @@ async fn run_node(node_config: Arc<GlobalConfig>, bootstrap: ConfigBootstrap) ->
Ok(())
}

fn enable_tracing_if_specified(bootstrap: &ConfigBootstrap) {
if bootstrap.tracing_enabled {
// To run: docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 -p14268:14268 \
// jaegertracing/all-in-one:latest
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name("tari::base_node")
.with_tags(vec![KeyValue::new("pid", process::id().to_string()), KeyValue::new("current_exe", env::current_exe().unwrap().to_str().unwrap_or_default().to_owned())])
// TODO: uncomment when using tokio 1
// .install_batch(opentelemetry::runtime::Tokio)
.install_simple()
.unwrap();
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
let subscriber = Registry::default().with(telemetry);
tracing::subscriber::set_global_default(subscriber)
.expect("Tracing could not be set. Try running without `--tracing-enabled`");
}
}

/// Runs the gRPC server
async fn run_grpc(
grpc: crate::grpc::base_node_grpc_server::BaseNodeGrpcServer,
Expand Down
9 changes: 9 additions & 0 deletions applications/tari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ tokio = { version="0.2.10", features = ["signal"] }
thiserror = "1.0.20"
tonic = "0.2"

tracing = "0.1.26"
tracing-opentelemetry = "0.15.0"
tracing-subscriber = "0.2.20"

# network tracing, rt-tokio for async batch export
opentelemetry = { version = "0.16", default-features = false, features = ["trace","rt-tokio"] }
opentelemetry-jaeger = { version="0.15", features=["rt-tokio"]}


[dependencies.tari_core]
path = "../../base_layer/core"
version = "^0.9"
Expand Down
24 changes: 23 additions & 1 deletion applications/tari_console_wallet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ use init::{
WalletBoot,
};
use log::*;
use opentelemetry::{self, global, KeyValue};
use recovery::prompt_private_key_from_seed_words;
use std::process;
use std::{env, process};
use tari_app_utilities::{consts, initialization::init_configuration, utilities::ExitCodes};
use tari_common::{configuration::bootstrap::ApplicationType, ConfigBootstrap};
use tari_core::transactions::types::PrivateKey;
use tari_shutdown::Shutdown;
use tracing_subscriber::{layer::SubscriberExt, Registry};
use wallet_modes::{command_mode, grpc_mode, recovery_mode, script_mode, tui_mode, WalletMode};

pub const LOG_TARGET: &str = "wallet::console_wallet::main";
Expand Down Expand Up @@ -90,6 +92,7 @@ fn main_inner() -> Result<(), ExitCodes> {
info!(target: LOG_TARGET, "Default configuration created. Done.");
}

enable_tracing_if_specified(&bootstrap);
// get command line password if provided
let arg_password = bootstrap.password.clone();
let seed_words_file_name = bootstrap.seed_words_file_name.clone();
Expand Down Expand Up @@ -185,3 +188,22 @@ fn get_recovery_master_key(
Ok(None)
}
}

fn enable_tracing_if_specified(bootstrap: &ConfigBootstrap) {
if bootstrap.tracing_enabled {
// To run: docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 -p14268:14268 \
// jaegertracing/all-in-one:latest
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name("tari::console_wallet")
.with_tags(vec![KeyValue::new("pid", process::id().to_string()), KeyValue::new("current_exe", env::current_exe().unwrap().to_str().unwrap_or_default().to_owned())])
// TODO: uncomment when using tokio 1
// .install_batch(opentelemetry::runtime::Tokio)
.install_simple()
.unwrap();
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
let subscriber = Registry::default().with(telemetry);
tracing::subscriber::set_global_default(subscriber)
.expect("Tracing could not be set. Try running without `--tracing-enabled`");
}
}
Loading