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

[sozo] add trace logs #1867

Merged
merged 28 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
741924c
Added trace logs for Sozo.
btirth Apr 22, 2024
ea535ab
Added Sozo trace logs.
btirth Apr 22, 2024
3a7bcd8
Added Sozo trace logs.
btirth Apr 22, 2024
dddbb05
Merge branch 'dojoengine:main' into 1409-sozo-trace-logs
btirth Apr 23, 2024
843507b
Merge branch 'dojoengine:main' into 1409-sozo-trace-logs
btirth Apr 23, 2024
fc0bdf2
Updated Sozo trace logs.
btirth Apr 23, 2024
1b40f20
Merge branch '1409-sozo-trace-logs' of github.com:btirth/dojo into 14…
btirth Apr 23, 2024
0229235
Updated Sozo trace logs.
btirth Apr 23, 2024
04ec215
Merge branch 'main' into 1409-sozo-trace-logs
btirth Apr 23, 2024
7b8a3fa
Updated Sozo trace logs
btirth Apr 24, 2024
d73c919
Merge branch 'dojoengine:main' into 1409-sozo-trace-logs
btirth Apr 24, 2024
ac24152
Updated Sozo trace logs.
btirth Apr 24, 2024
066dcaa
Updated Sozo trace logs
btirth Apr 24, 2024
2c4124d
Updated Sozo trace logs.
btirth Apr 24, 2024
5bb716a
Removed json for Sozo log.
btirth Apr 25, 2024
b7e0319
Resolved merge conflicts.
btirth Apr 25, 2024
1d66680
Removed LOG_TARGET for Sozo trace logs.
btirth Apr 26, 2024
ecc407f
Merge branch 'dojoengine:main' into 1409-sozo-trace-logs
btirth Apr 26, 2024
4e4f539
Merge branch '1409-sozo-trace-logs' of github.com:btirth/dojo into 14…
btirth Apr 26, 2024
d8ee5ec
Updated Sozo trace logs
btirth Apr 27, 2024
fc2b5c0
Updated Sozo trace logs - removed fetch keyword.
btirth Apr 27, 2024
0a305bc
Resolved merge conflicts.
btirth Apr 27, 2024
b36d0d0
Merge branch 'dojoengine:main' into 1409-sozo-trace-logs
btirth Apr 29, 2024
e1b71a0
Resolved failing checks.
btirth Apr 29, 2024
182ee2e
Updated Sozo trace logs.
btirth Apr 30, 2024
4449b7e
Merge branch 'dojoengine:main' into 1409-sozo-trace-logs
btirth Apr 30, 2024
f68986f
Updated Sozo trace logs.
btirth Apr 30, 2024
a741fa9
fix: ensure sozo commands return expected Result
glihm Apr 30, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bin/sozo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ thiserror.workspace = true
tokio.workspace = true
tracing-log = "0.1.3"
tracing.workspace = true
tracing-subscriber.workspace = true
url.workspace = true
katana-rpc-api.workspace = true

Expand Down
14 changes: 14 additions & 0 deletions bin/sozo/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use scarb::compiler::Profile;
use scarb_ui::Verbosity;
use smol_str::SmolStr;
use tracing::level_filters::LevelFilter;
use tracing::Subscriber;
use tracing_log::AsTrace;
use tracing_subscriber::{fmt, EnvFilter};

use crate::commands::Commands;
use crate::utils::generate_version;
Expand Down Expand Up @@ -50,6 +52,18 @@ impl SozoArgs {
Verbosity::Quiet
}
}

pub fn init_logging(&self) -> Result<(), Box<dyn std::error::Error>> {
const DEFAULT_LOG_FILTER: &str = "info,hyper=off,scarb=off";

let builder = fmt::Subscriber::builder().with_env_filter(
EnvFilter::try_from_default_env().or(EnvFilter::try_new(DEFAULT_LOG_FILTER))?,
);

let subscriber: Box<dyn Subscriber + Send + Sync> = Box::new(builder.finish());

Ok(tracing::subscriber::set_global_default(subscriber)?)
}
}

/// Profile specifier.
Expand Down
17 changes: 16 additions & 1 deletion bin/sozo/src/commands/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use sozo_ops::account;
use starknet::signers::LocalWallet;
use starknet_crypto::FieldElement;
use tracing::trace;

use super::options::fee::FeeOptions;
use super::options::signer::SignerOptions;
Expand Down Expand Up @@ -83,12 +84,14 @@

impl AccountArgs {
pub fn run(self, config: &Config) -> Result<()> {
trace!(command = ?self.command, "Executing command.");
let env_metadata = utils::load_metadata_from_config(config)?;

config.tokio_handle().block_on(async {
match self.command {
AccountCommand::New { signer, force, file } => {
let signer: LocalWallet = signer.signer(env_metadata.as_ref(), false)?;
trace!(?signer, force, ?file, "Executing New command.");
account::new(signer, force, file).await
}
AccountCommand::Deploy {
Expand All @@ -102,8 +105,19 @@
no_confirmation,
} => {
let provider = starknet.provider(env_metadata.as_ref())?;
let signer = signer.signer(env_metadata.as_ref(), false)?;
let signer: LocalWallet = signer.signer(env_metadata.as_ref(), false)?;

Check warning on line 108 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L108

Added line #L108 was not covered by tests
let fee_setting = fee.into_setting()?;
trace!(
?starknet,
?signer,
?fee_setting,
simulate,
?nonce,
poll_interval,
?file,
no_confirmation,
"Executing Deploy command."
);

Check warning on line 120 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L110-L120

Added lines #L110 - L120 were not covered by tests
account::deploy(
provider,
signer,
Expand All @@ -117,6 +131,7 @@
.await
}
AccountCommand::Fetch { starknet, force, output, address } => {
trace!(?starknet, force, ?output, ?address, "Executing Fetch command.");

Check warning on line 134 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L134

Added line #L134 was not covered by tests
let provider = starknet.provider(env_metadata.as_ref())?;
account::fetch(provider, force, output, address).await
}
Expand Down
22 changes: 22 additions & 0 deletions bin/sozo/src/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use dojo_world::metadata::Environment;
use scarb::core::Config;
use sozo_ops::auth;
use tracing::trace;

use super::options::account::AccountOptions;
use super::options::starknet::StarknetOptions;
Expand Down Expand Up @@ -56,7 +57,10 @@

impl AuthArgs {
pub fn run(self, config: &Config) -> Result<()> {
trace!(command=?self.command, "Executing Auth command.", );

Check warning on line 60 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L60

Added line #L60 was not covered by tests

let env_metadata = utils::load_metadata_from_config(config)?;
trace!(metadata=?env_metadata, "Loaded environment.");

Check warning on line 63 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L63

Added line #L63 was not covered by tests

match self.command {
AuthCommand::Grant { kind, world, starknet, account, transaction } => config
Expand Down Expand Up @@ -102,14 +106,23 @@
kind: AuthKind,
transaction: TransactionOptions,
) -> Result<()> {
trace!(?kind, ?world, ?starknet, ?account, ?transaction, "Executing Grant command.");

Check warning on line 109 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L109

Added line #L109 was not covered by tests
let world =
utils::world_from_env_metadata(world, account, starknet, &env_metadata).await.unwrap();

match kind {
AuthKind::Writer { models_contracts } => {
trace!(
contracts=?models_contracts,
"Granting Writer permissions."
);

Check warning on line 118 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L115-L118

Added lines #L115 - L118 were not covered by tests
auth::grant_writer(&world, models_contracts, transaction.into()).await
}
AuthKind::Owner { owners_resources } => {
trace!(
resources=?owners_resources,
"Granting Owner permissions."
);

Check warning on line 125 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L122-L125

Added lines #L122 - L125 were not covered by tests
auth::grant_owner(&world, owners_resources, transaction.into()).await
}
}
Expand All @@ -123,13 +136,22 @@
kind: AuthKind,
transaction: TransactionOptions,
) -> Result<()> {
trace!(?kind, ?world, ?starknet, ?account, ?transaction, "Executing Revoke command.");

Check warning on line 139 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L139

Added line #L139 was not covered by tests
let world =
utils::world_from_env_metadata(world, account, starknet, &env_metadata).await.unwrap();
match kind {
AuthKind::Writer { models_contracts } => {
trace!(
contracts=?models_contracts,
"Revoking Writer permissions."
);

Check warning on line 147 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L144-L147

Added lines #L144 - L147 were not covered by tests
auth::revoke_writer(&world, models_contracts, transaction.into()).await
}
AuthKind::Owner { owners_resources } => {
trace!(
resources=?owners_resources,
"Revoking Owner permissions."
);

Check warning on line 154 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L151-L154

Added lines #L151 - L154 were not covered by tests
auth::revoke_owner(&world, owners_resources, transaction.into()).await
}
}
Expand Down
10 changes: 9 additions & 1 deletion bin/sozo/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use scarb::core::{Config, TargetKind};
use scarb::ops::CompileOpts;
use sozo_ops::statistics::{get_contract_statistics_for_dir, ContractStatistics};
use tracing::trace;

#[derive(Debug, Args)]
pub struct BuildArgs {
Expand Down Expand Up @@ -36,6 +37,7 @@
config,
CompileOpts { include_targets: vec![], exclude_targets: vec![TargetKind::TEST] },
)?;
trace!(?compile_info, "Compiled workspace.");

let mut builtin_plugins = vec![];
if self.typescript {
Expand All @@ -54,6 +56,12 @@
let target_dir = &compile_info.target_dir;
let contracts_statistics = get_contract_statistics_for_dir(target_dir)
.context("Error getting contracts stats")?;
trace!(
?contracts_statistics,
?target_dir,
"Read contract statistics for target directory."
);

Check warning on line 63 in bin/sozo/src/commands/build.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/build.rs#L60-L63

Added lines #L60 - L63 were not covered by tests

let table = create_stats_table(contracts_statistics);
table.printstd()
}
Expand All @@ -69,6 +77,7 @@
plugins: vec![],
builtin_plugins,
};
trace!(pluginManager=?bindgen, "Generating bindings.");

tokio::runtime::Runtime::new()
.unwrap()
Expand All @@ -95,7 +104,6 @@
let contract_name = contract_stats.contract_name;
let number_felts = contract_stats.number_felts;
let file_size = contract_stats.file_size;

table.add_row(Row::new(vec![
Cell::new_align(&contract_name, format::Alignment::LEFT),
Cell::new_align(format!("{}", number_felts).as_str(), format::Alignment::RIGHT),
Expand Down
5 changes: 4 additions & 1 deletion bin/sozo/src/commands/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use clap::Args;
use scarb::core::Config;
use starknet::core::types::FieldElement;
use tracing::trace;

use super::options::starknet::StarknetOptions;
use super::options::world::WorldOptions;
Expand Down Expand Up @@ -35,8 +36,10 @@

impl CallArgs {
pub fn run(self, config: &Config) -> Result<()> {
let env_metadata = utils::load_metadata_from_config(config)?;
trace!(contract=?self.contract, entrypoint=self.entrypoint, calldata=?self.calldata, block_id=self.block_id, "Executing Call command.");

Check warning on line 39 in bin/sozo/src/commands/call.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/call.rs#L39

Added line #L39 was not covered by tests

let env_metadata = utils::load_metadata_from_config(config)?;
trace!(?env_metadata, "Loaded metadata from config.");

Check warning on line 42 in bin/sozo/src/commands/call.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/call.rs#L41-L42

Added lines #L41 - L42 were not covered by tests
config.tokio_handle().block_on(async {
let world_reader =
utils::world_reader_from_env_metadata(self.world, self.starknet, &env_metadata)
Expand Down
6 changes: 6 additions & 0 deletions bin/sozo/src/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use camino::Utf8PathBuf;
use clap::Args;
use dojo_lang::compiler::{ABIS_DIR, BASE_DIR, MANIFESTS_DIR};
use scarb::core::Config;
use tracing::trace;

#[derive(Debug, Args)]
pub struct CleanArgs {
Expand All @@ -21,10 +22,12 @@ impl CleanArgs {
///
/// * `profile_dir` - The directory where the profile files are located.
pub fn clean_manifests(&self, profile_dir: &Utf8PathBuf) -> Result<()> {
trace!(?profile_dir, "Cleaning manifests.");
let dirs = vec![profile_dir.join(BASE_DIR), profile_dir.join(ABIS_DIR).join(BASE_DIR)];

for d in dirs {
if d.exists() {
trace!(directory=?d, "Removing directory.");
fs::remove_dir_all(d)?;
}
}
Expand All @@ -34,6 +37,7 @@ impl CleanArgs {

pub fn run(self, config: &Config) -> Result<()> {
let ws = scarb::ops::read_workspace(config.manifest_path(), config)?;
trace!(ws=?ws, "Workspace read successfully.");

let profile_name =
ws.current_profile().expect("Scarb profile is expected at this point.").to_string();
Expand All @@ -45,10 +49,12 @@ impl CleanArgs {
let profile_dir = manifest_dir.join(MANIFESTS_DIR).join(profile_name);

// By default, this command cleans the build manifests and scarb artifacts.
trace!("Cleaning Scarb artifacts and build manifests.");
scarb::ops::clean(config)?;
self.clean_manifests(&profile_dir)?;

if self.all && profile_dir.exists() {
trace!(?profile_dir, "Removing entire profile directory.");
fs::remove_dir_all(profile_dir)?;
}

Expand Down
22 changes: 14 additions & 8 deletions bin/sozo/src/commands/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
use starknet::core::types::FieldElement;
use starknet::providers::Provider;
use starknet::signers::Signer;
use tracing::error;
use tracing::{error, trace};

use super::migrate::setup_env;
use super::options::account::AccountOptions;
use super::options::starknet::StarknetOptions;
use super::options::world::WorldOptions;

pub(crate) const LOG_TARGET: &str = "sozo::cli::commands::dev";

#[derive(Debug, Args)]
pub struct DevArgs {
#[arg(long)]
Expand All @@ -57,10 +55,12 @@
let env_metadata = if config.manifest_path().exists() {
dojo_metadata_from_workspace(&ws).env().cloned()
} else {
trace!("Manifest path does not exist.");

Check warning on line 58 in bin/sozo/src/commands/dev.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/dev.rs#L58

Added line #L58 was not covered by tests
None
};

let mut context = load_context(config)?;

let (tx, rx) = channel();
let mut debouncer = new_debouncer(Duration::from_secs(1), None, tx)?;

Expand Down Expand Up @@ -88,7 +88,7 @@
))
.ok()
else {
return Err(anyhow!("Failed to setup environment"));
return Err(anyhow!("Failed to setup environment."));

Check warning on line 91 in bin/sozo/src/commands/dev.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/dev.rs#L91

Added line #L91 was not covered by tests
};

match context.ws.config().tokio_handle().block_on(migrate(
Expand All @@ -104,7 +104,6 @@
}
Err(error) => {
error!(
target: LOG_TARGET,
error = ?error,
address = ?world_address,
"Migrating world."
Expand All @@ -120,7 +119,7 @@
.unwrap_or(DevAction::None),
Ok(Err(_)) => DevAction::None,
Err(error) => {
error!(target: LOG_TARGET, error = ?error, "Receiving dev action.");
error!(error = ?error, "Receiving dev action.");

Check warning on line 122 in bin/sozo/src/commands/dev.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/dev.rs#L122

Added line #L122 was not covered by tests
break;
}
};
Expand All @@ -139,7 +138,6 @@
}
Err(error) => {
error!(
target: LOG_TARGET,
error = ?error,
address = ?world_address,
"Migrating world.",
Expand All @@ -152,7 +150,7 @@
}
}

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]

Check warning on line 153 in bin/sozo/src/commands/dev.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/dev.rs#L153

Added line #L153 was not covered by tests
enum DevAction {
None,
Reload,
Expand All @@ -176,6 +174,8 @@
}
_ => DevAction::None,
};

trace!(?action, "Determined action.");

Check warning on line 178 in bin/sozo/src/commands/dev.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/dev.rs#L178

Added line #L178 was not covered by tests
action
}

Expand All @@ -196,6 +196,7 @@

// we have only 1 unit in projects
// TODO: double check if we always have one with the new version and the order if many.
trace!(unit_count = compilation_units.len(), "Gathering compilation units.");

Check warning on line 199 in bin/sozo/src/commands/dev.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/dev.rs#L199

Added line #L199 was not covered by tests
let unit = compilation_units.first().unwrap();
let db = build_scarb_root_database(unit).unwrap();
Ok(DevContext { db, unit: unit.clone(), ws })
Expand Down Expand Up @@ -267,6 +268,7 @@
}

fn process_event(event: &DebouncedEvent, context: &mut DevContext<'_>) -> DevAction {
trace!(event=?event, "Processing event.");

Check warning on line 271 in bin/sozo/src/commands/dev.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/dev.rs#L271

Added line #L271 was not covered by tests
let action = handle_event(event);
match &action {
DevAction::None => {}
Expand All @@ -275,6 +277,8 @@
handle_reload_action(context);
}
}

trace!(action=?action, "Processed action.");

Check warning on line 281 in bin/sozo/src/commands/dev.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/dev.rs#L281

Added line #L281 was not covered by tests
action
}

Expand All @@ -291,8 +295,10 @@
}

fn handle_reload_action(context: &mut DevContext<'_>) {
trace!("Reloading context.");

Check warning on line 298 in bin/sozo/src/commands/dev.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/dev.rs#L298

Added line #L298 was not covered by tests
let config = context.ws.config();
config.ui().print("Reloading project");
let new_context = load_context(config).expect("Failed to load context");
let _ = mem::replace(context, new_context);
trace!("Context reloaded.");

Check warning on line 303 in bin/sozo/src/commands/dev.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/dev.rs#L303

Added line #L303 was not covered by tests
}
Loading
Loading