Skip to content

Commit

Permalink
linera-service: attach spans for node service port and chain ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Twey committed Jul 17, 2024
1 parent b3c4ba2 commit 2c001d3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
21 changes: 13 additions & 8 deletions linera-client/src/chain_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use linera_core::{
use linera_execution::{Message, SystemMessage};
use linera_storage::Storage;
use linera_views::views::ViewError;
use tracing::{error, info, warn};
use tracing::{error, info, warn, Instrument as _};

use crate::{chain_clients::ChainClients, wallet::Wallet};

Expand Down Expand Up @@ -110,6 +110,7 @@ where
}
}

#[tracing::instrument(level = "trace", skip_all, fields(?chain_id))]
fn run_with_chain_id<C>(
chain_id: ChainId,
clients: ChainClients<P, S>,
Expand All @@ -119,15 +120,19 @@ where
) where
C: ClientContext<ValidatorNodeProvider = P, Storage = S> + Send + 'static,
{
let _handle = tokio::task::spawn(async move {
if let Err(err) =
Self::run_client_stream(chain_id, clients, context, storage, config).await
{
error!("Stream for chain {} failed: {}", chain_id, err);
let _handle = tokio::task::spawn(
async move {
if let Err(err) =
Self::run_client_stream(chain_id, clients, context, storage, config).await
{
error!("Stream for chain {} failed: {}", chain_id, err);
}
}
});
.in_current_span(),
);
}

#[tracing::instrument(level = "trace", skip_all, fields(?chain_id))]
async fn run_client_stream<C>(
chain_id: ChainId,
clients: ChainClients<P, S>,
Expand All @@ -153,7 +158,7 @@ where
};
let (listener, _listen_handle, mut local_stream) = client.listen().await?;
client.synchronize_from_validators().await?;
tokio::spawn(listener);
tokio::spawn(listener.in_current_span());
let mut timeout = storage.clock().current_time();
loop {
let sleep = Box::pin(storage.clock().sleep_until(timeout));
Expand Down
8 changes: 4 additions & 4 deletions linera-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use serde::Serialize;
use thiserror::Error;
use tokio::sync::{Mutex, OwnedRwLockReadGuard};
use tokio_stream::wrappers::UnboundedReceiverStream;
use tracing::{debug, error, info};
use tracing::{debug, error, info, Instrument as _};

use crate::{
data_types::{
Expand Down Expand Up @@ -2647,7 +2647,7 @@ where
}
}

#[tracing::instrument(level = "trace", skip(self))]
#[tracing::instrument(level = "trace", skip(self), fields(chain_id = ?self.chain_id))]
/// Spawns a task that listens to notifications about the current chain from all validators,
/// and synchronizes the local state accordingly.
pub async fn listen(
Expand All @@ -2658,7 +2658,6 @@ where
{
use future::FutureExt as _;

#[tracing::instrument(level = "trace", skip(future, background_work))]
async fn await_while_polling<F: FusedFuture>(
future: F,
background_work: impl FusedStream<Item = ()>,
Expand Down Expand Up @@ -2719,7 +2718,8 @@ where
}

let () = process_notifications.collect().await;
};
}
.in_current_span();

Ok((update_streams, AbortOnDrop(abort), notifications))
}
Expand Down
6 changes: 6 additions & 0 deletions linera-service/src/linera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,12 @@ fn main() -> anyhow::Result<()> {
}

async fn run(options: &ClientOptions) -> anyhow::Result<()> {
let span = tracing::info_span!("run");
if let Some(wallet_id) = options.with_wallet {
span.record("wallet_id", wallet_id);
}
let _entered = span.enter();

match &options.command {
ClientCommand::HelpMarkdown => {
clap_markdown::print_help_markdown::<ClientOptions>();
Expand Down
3 changes: 3 additions & 0 deletions linera-service/src/node_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,9 @@ where
let application_handler =
axum::routing::get(util::graphiql).post(Self::application_handler);

let span = tracing::info_span!("node_service", port);
let _entered = span.enter();

let app = Router::new()
.route("/", index_handler)
.route(
Expand Down

0 comments on commit 2c001d3

Please sign in to comment.