refactor init tracer and use of tracing_opentelemetry span for async tracing
This commit is contained in:
@@ -8,7 +8,7 @@ use crate::node::mixnet::packet_forwarding::global::is_global_ip;
|
||||
use crate::node::NymNode;
|
||||
use std::fs;
|
||||
use std::net::IpAddr;
|
||||
use tracing::{debug, info, instrument, trace, warn};
|
||||
use tracing::{debug, info, instrument, Instrument, trace, warn};
|
||||
|
||||
mod args;
|
||||
|
||||
@@ -125,5 +125,5 @@ pub(crate) async fn execute(mut args: Args) -> Result<(), NymNodeError> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
nym_node.run().await
|
||||
nym_node.run().in_current_span().await
|
||||
}
|
||||
|
||||
+83
-26
@@ -17,7 +17,9 @@ use nym_bin_common::logging::error::TracingError;
|
||||
#[cfg(feature = "otel")]
|
||||
use nym_bin_common::opentelemetry::setup_tracing_logger;
|
||||
#[cfg(feature = "otel")]
|
||||
use opentelemetry::{Context, global, trace::{TraceContextExt, Tracer}};
|
||||
use opentelemetry::{global, trace::{TraceContextExt, Tracer}};
|
||||
#[cfg(feature = "otel")]
|
||||
use tracing::Instrument;
|
||||
use std::future::Future;
|
||||
use std::sync::OnceLock;
|
||||
use tracing::instrument;
|
||||
@@ -92,48 +94,103 @@ impl Cli {
|
||||
// SigNoz/OTEL run in async context
|
||||
Commands::BondingInformation(args) => Self::execute_async(async move {
|
||||
#[cfg(feature = "otel")]
|
||||
setup_tracing_logger("nym-node".to_string())
|
||||
.map_err(TracingError::from)?;
|
||||
{
|
||||
let _guard = setup_tracing_logger("nym-node".to_string())
|
||||
.map_err(TracingError::from)?;
|
||||
let main_span = tracing::info_span!("startup", service = "nym-node");
|
||||
async {
|
||||
bonding_information::execute(args).in_current_span().await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
}
|
||||
.instrument(main_span)
|
||||
.await
|
||||
}
|
||||
#[cfg(not(feature = "otel"))]
|
||||
setup_no_otel_logger().expect("failed to initialize logging");
|
||||
bonding_information::execute(args).await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
{
|
||||
setup_no_otel_logger().expect("failed to initialize logging");
|
||||
bonding_information::execute(args).await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
}
|
||||
})??,
|
||||
Commands::NodeDetails(args) => Self::execute_async(async move {
|
||||
#[cfg(feature = "otel")]
|
||||
setup_tracing_logger("nym-node".to_string())
|
||||
.map_err(TracingError::from)?;
|
||||
{
|
||||
let _guard = setup_tracing_logger("nym-node".to_string())
|
||||
.map_err(TracingError::from)?;
|
||||
let main_span = tracing::info_span!("startup", service = "nym-node");
|
||||
async {
|
||||
node_details::execute(args).in_current_span().await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
}
|
||||
.instrument(main_span)
|
||||
.await
|
||||
}
|
||||
#[cfg(not(feature = "otel"))]
|
||||
setup_no_otel_logger().expect("failed to initialize logging");
|
||||
node_details::execute(args).await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
{
|
||||
setup_no_otel_logger().expect("failed to initialize logging");
|
||||
node_details::execute(args).await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
}
|
||||
})??,
|
||||
Commands::Run(args) => Self::execute_async(async move {
|
||||
#[cfg(feature = "otel")]
|
||||
setup_tracing_logger("nym-node".to_string())
|
||||
.map_err(TracingError::from)?;
|
||||
{
|
||||
let _guard = setup_tracing_logger("nym-node".to_string())
|
||||
.map_err(TracingError::from)?;
|
||||
let main_span = tracing::info_span!("startup", service = "nym-node");
|
||||
async {
|
||||
run::execute(*args).in_current_span().await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
}
|
||||
.instrument(main_span)
|
||||
.await
|
||||
}
|
||||
#[cfg(not(feature = "otel"))]
|
||||
setup_no_otel_logger().expect("failed to initialize logging");
|
||||
run::execute(*args).await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
{
|
||||
setup_no_otel_logger().expect("failed to initialize logging");
|
||||
run::execute(*args).await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
}
|
||||
})??,
|
||||
Commands::Sign(args) => Self::execute_async(async move {
|
||||
#[cfg(feature = "otel")]
|
||||
setup_tracing_logger("nym-node".to_string())
|
||||
.map_err(TracingError::from)?;
|
||||
{
|
||||
let _guard = setup_tracing_logger("nym-node".to_string())
|
||||
.map_err(TracingError::from)?;
|
||||
let main_span = tracing::info_span!("startup", service = "nym-node");
|
||||
async {
|
||||
sign::execute(args).in_current_span().in_current_span().await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
}
|
||||
.instrument(main_span)
|
||||
.await
|
||||
}
|
||||
#[cfg(not(feature = "otel"))]
|
||||
setup_no_otel_logger().expect("failed to initialize logging");
|
||||
sign::execute(args).await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
{
|
||||
setup_no_otel_logger().expect("failed to initialize logging");
|
||||
sign::execute(args).await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
}
|
||||
})??,
|
||||
Commands::UnsafeResetSphinxKeys(args) => Self::execute_async(async move {
|
||||
#[cfg(feature = "otel")]
|
||||
setup_tracing_logger("nym-node".to_string())
|
||||
.map_err(TracingError::from)?;
|
||||
{
|
||||
let _guard = setup_tracing_logger("nym-node".to_string())
|
||||
.map_err(TracingError::from)?;
|
||||
let main_span = tracing::info_span!("startup", service = "nym-node");
|
||||
async {
|
||||
reset_sphinx_keys::execute(args).in_current_span().await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
}
|
||||
.instrument(main_span)
|
||||
.await
|
||||
}
|
||||
#[cfg(not(feature = "otel"))]
|
||||
setup_no_otel_logger().expect("failed to initialize logging");
|
||||
reset_sphinx_keys::execute(args).await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
{
|
||||
setup_no_otel_logger().expect("failed to initialize logging");
|
||||
reset_sphinx_keys::execute(args).await?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
}
|
||||
})??,
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user