Skip to content

Commit

Permalink
feat: add tracing to each command
Browse files Browse the repository at this point in the history
  • Loading branch information
karlem committed Jul 18, 2024
1 parent b348fe0 commit 9f8f27a
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 14 deletions.
16 changes: 16 additions & 0 deletions fendermint/app/config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ host = "127.0.0.1"
# The default port where the Prometheus exporter makes the metrics available.
port = 9184

[tracing]

[tracing.console]
enabled = true

[tracing.file]
enabled = false

[snapshots]
# Enable the export and import of snapshots.
enabled = false
Expand Down Expand Up @@ -149,6 +157,14 @@ host = "127.0.0.1"
port = 9185


[eth.tracing]

[eth.tracing.console]
enabled = true

[eth.tracing.file]
enabled = false

# IPLD Resolver Configuration
[resolver]
# Time to wait between attempts to resolve a CID after an error.
Expand Down
7 changes: 6 additions & 1 deletion fendermint/app/src/cmd/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use fendermint_app_options::debug::{
DebugArgs, DebugCommands, DebugExportTopDownEventsArgs, DebugIpcCommands,
};
use fendermint_vm_topdown::proxy::IPCProviderProxy;
use ipc_observability::traces::set_global_tracing_subscriber;
use ipc_observability::traces_settings::TracesSettings;
use ipc_provider::{
config::subnet::{EVMSubnet, SubnetConfig},
IpcProvider,
Expand All @@ -23,9 +25,12 @@ cmd! {

cmd! {
DebugIpcCommands(self) {
let _trace_file_guard = set_global_tracing_subscriber(&TracesSettings::default())?;

match self {
DebugIpcCommands::ExportTopDownEvents(args) =>
DebugIpcCommands::ExportTopDownEvents(args) => {
export_topdown_events(args).await
}
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions fendermint/app/src/cmd/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use crate::{

cmd! {
EthArgs(self, settings: EthSettings) {
let _trace_file_guard = set_global_tracing_subscriber(&settings.tracing)?;

match self.command.clone() {
EthCommands::Run { ws_url, http_url, connect_retry_delay } => {

let (client, driver) = HybridClient::new(http_url, ws_url, Duration::from_secs(connect_retry_delay)).context("failed to create HybridClient")?;

let driver_handle = tokio::spawn(async move { driver.run().await });
Expand All @@ -35,8 +36,6 @@ cmd! {

/// Run the Ethereum API facade.
async fn run(settings: EthSettings, client: HybridClient) -> anyhow::Result<()> {
// TOOO kare - set up tracing

if settings.metrics.enabled {
info!("metrics enabled");

Expand Down
4 changes: 4 additions & 0 deletions fendermint/app/src/cmd/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use fendermint_vm_genesis::{
ipc, Account, Actor, ActorMeta, Collateral, Genesis, Multisig, PermissionMode, SignerAddr,
Validator, ValidatorKey,
};
use ipc_observability::traces::set_global_tracing_subscriber;
use ipc_observability::traces_settings::TracesSettings;

use crate::cmd;
use crate::options::genesis::*;
Expand All @@ -22,7 +24,9 @@ use super::key::read_public_key;

cmd! {
GenesisArgs(self) {
let _trace_file_guard = set_global_tracing_subscriber(&TracesSettings::default())?;
let genesis_file = self.genesis_file.clone();

match &self.command {
GenesisCommands::New(args) => args.exec(genesis_file).await,
GenesisCommands::AddAccount(args) => args.exec(genesis_file).await,
Expand Down
4 changes: 4 additions & 0 deletions fendermint/app/src/cmd/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use fendermint_app_options::key::KeyShowPeerIdArgs;
use fendermint_crypto::{from_b64, to_b64, PublicKey, SecretKey};
use fendermint_vm_actor_interface::eam::EthAddress;
use fvm_shared::address::Address;
use ipc_observability::traces::set_global_tracing_subscriber;
use ipc_observability::traces_settings::TracesSettings;
use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng};
use serde_json::json;
use std::path::Path;
Expand All @@ -21,6 +23,8 @@ use crate::{

cmd! {
KeyArgs(self) {
let _trace_file_guard = set_global_tracing_subscriber(&TracesSettings::default())?;

match &self.command {
KeyCommands::Gen(args) => args.exec(()).await,
KeyCommands::IntoTendermint(args) => args.exec(()).await,
Expand Down
4 changes: 4 additions & 0 deletions fendermint/app/src/cmd/materializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ use fendermint_materializer::{
testnet::Testnet,
AccountId, TestnetId, TestnetName,
};
use ipc_observability::traces::set_global_tracing_subscriber;
use ipc_observability::traces_settings::TracesSettings;

use crate::cmd;

use super::key::{read_secret_key, read_secret_key_hex};

cmd! {
MaterializerArgs(self) {
let _trace_file_guard = set_global_tracing_subscriber(&TracesSettings::default())?;

let data_dir = expand_tilde(&self.data_dir);
let dm = || DockerMaterializer::new(&data_dir, self.seed).map(|m| m.with_policy(DropPolicy::PERSISTENT));
let lm = || dm().map(|m| LoggingMaterializer::new(m, "cli".to_string()));
Expand Down
4 changes: 4 additions & 0 deletions fendermint/app/src/cmd/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use tendermint_rpc::HttpClient;
use fendermint_rpc::message::{GasParams, SignedMessageFactory};
use fendermint_rpc::{client::FendermintClient, query::QueryClient};
use fendermint_vm_actor_interface::eam::{self, CreateReturn, EthAddress};
use ipc_observability::traces::set_global_tracing_subscriber;
use ipc_observability::traces_settings::TracesSettings;

use crate::cmd;
use crate::options::rpc::{BroadcastMode, FevmArgs, RpcFevmCommands, TransArgs};
Expand All @@ -40,6 +42,8 @@ use super::key::read_secret_key;

cmd! {
RpcArgs(self) {
let _trace_file_guard = set_global_tracing_subscriber(&TracesSettings::default())?;

let client = FendermintClient::new_http(self.url.clone(), self.proxy_url.clone())?;
match self.command.clone() {
RpcCommands::Query { height, command } => {
Expand Down
4 changes: 2 additions & 2 deletions fendermint/app/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ use ipc_observability::traces::set_global_tracing_subscriber;

cmd! {
RunArgs(self, settings) {
let _trace_file_guard = set_global_tracing_subscriber(&settings.tracing)?;

run(settings).await
}
}
Expand All @@ -61,8 +63,6 @@ namespaces! {
///
/// This method acts as our composition root.
async fn run(settings: Settings) -> anyhow::Result<()> {
let _work_guard = set_global_tracing_subscriber(&settings.tracing)?;

let tendermint_rpc_url = settings.tendermint_rpc_url()?;
tracing::info!("Connecting to Tendermint at {tendermint_rpc_url}");

Expand Down
20 changes: 17 additions & 3 deletions ipc/observability/src/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use tracing_appender::non_blocking::WorkerGuard;
use tracing_appender::rolling::RollingFileAppender;
use tracing_subscriber::{fmt, fmt::Subscriber, layer::SubscriberExt, Layer};

use crate::traces_settings::{FileLayerSettings, TracesSettings};
use crate::traces_settings::{FileLayerSettings, LogLevel, TracesSettings};
use crate::tracing_layers::DomainEventFilterLayer;
use anyhow::Result;

Expand All @@ -29,7 +29,14 @@ pub fn set_global_tracing_subscriber(config: &TracesSettings) -> Result<WorkerGu
.with_target(false)
.with_file(true)
.with_line_number(true)
.with_filter(config.console.level.to_filter()?);
.with_filter(
config
.console
.level
.as_ref()
.unwrap_or(&LogLevel::default())
.to_filter()?,
);

let (file_layer, file_guard) = if config.file.enabled {
let (non_blocking, file_guard) = non_blocking(create_file_appender(&config.file));
Expand All @@ -41,7 +48,14 @@ pub fn set_global_tracing_subscriber(config: &TracesSettings) -> Result<WorkerGu
.with_target(false)
.with_file(true)
.with_line_number(true)
.with_filter(config.file.level.to_filter()?);
.with_filter(
config
.file
.level
.as_ref()
.unwrap_or(&LogLevel::default())
.to_filter()?,
);

let domains = config
.file
Expand Down
9 changes: 4 additions & 5 deletions ipc/observability/src/traces_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl FromStr for RotationKind {
}

#[serde_as]
#[derive(Debug, Deserialize, Clone)]
#[derive(Debug, Deserialize, Clone, Default)]
pub struct TracesSettings {
pub console: ConsoleLayerSettings,
pub file: FileLayerSettings,
Expand All @@ -85,24 +85,23 @@ pub struct TracesSettings {
#[derive(Debug, Deserialize, Clone)]
pub struct ConsoleLayerSettings {
pub enabled: bool,
pub level: LogLevel,
pub level: Option<LogLevel>,
}

impl Default for ConsoleLayerSettings {
fn default() -> Self {
ConsoleLayerSettings {
enabled: true,
level: LogLevel::default(),
level: Some(LogLevel::default()),
}
}
}

#[serde_as]
#[derive(Debug, Deserialize, Clone, Default)]

pub struct FileLayerSettings {
pub enabled: bool,
pub level: LogLevel,
pub level: Option<LogLevel>,
pub directory: Option<PathBuf>,
pub max_log_files: Option<usize>,
pub rotation: Option<RotationKind>,
Expand Down

0 comments on commit 9f8f27a

Please sign in to comment.