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 19 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
15 changes: 14 additions & 1 deletion bin/sozo/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use scarb_ui::Verbosity;
use smol_str::SmolStr;
use tracing::level_filters::LevelFilter;
use tracing_log::AsTrace;

use tracing::Subscriber;
use tracing_subscriber::{fmt, EnvFilter};
use crate::commands::Commands;
use crate::utils::generate_version;

Expand Down Expand Up @@ -50,6 +51,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
30 changes: 29 additions & 1 deletion bin/sozo/src/commands/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use super::options::signer::SignerOptions;
use super::options::starknet::StarknetOptions;
use crate::utils;
use tracing::trace;

#[derive(Debug, Args)]
pub struct AccountArgs {
Expand Down Expand Up @@ -83,12 +84,20 @@

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."
);

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

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L96-L100

Added lines #L96 - L100 were not covered by tests
account::new(signer, force, file).await
}
AccountCommand::Deploy {
Expand All @@ -101,9 +110,21 @@
file,
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 115 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L115 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 127 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L117-L127

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

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

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L141-L147

Added lines #L141 - L147 were 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
6 changes: 5 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 prettytable::{format, Cell, Row, Table};
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 @@ impl BuildArgs {
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,8 @@ impl BuildArgs {
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, "Fetched contract statistics for target directory.");
btirth marked this conversation as resolved.
Show resolved Hide resolved

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

tokio::runtime::Runtime::new()
.unwrap()
Expand All @@ -95,7 +100,6 @@ fn create_stats_table(contracts_statistics: Vec<ContractStatistics>) -> Table {
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
6 changes: 5 additions & 1 deletion bin/sozo/src/commands/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use super::options::starknet::StarknetOptions;
use super::options::world::WorldOptions;
use crate::utils;
use tracing::trace;

#[derive(Debug, Args)]
#[command(about = "Call a system with the given calldata.")]
Expand Down Expand Up @@ -35,9 +36,12 @@

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, "Fetched environment metadata.");

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
btirth marked this conversation as resolved.
Show resolved Hide resolved
config.tokio_handle().block_on(async {

let world_reader =
utils::world_reader_from_env_metadata(self.world, self.starknet, &env_metadata)
.await
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
Loading
Loading