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

feat: add rpc logging #75

Merged
merged 3 commits into from
Feb 11, 2022
Merged

Conversation

itegulov
Copy link
Contributor

@itegulov itegulov commented Feb 9, 2022

This PR adds logging to RPC client. I made the logs dynamic depending on the logging level enabled. Usually INFO would be enough for most users as it prints one-liners with submitted actions and the resulting status. But if a user wants more information (e.g. gas profile, logs etc), they can enable DEBUG. Try it out by running tests with RUST_LOG=workspaces=info.

pub(crate) async fn query_broadcast_tx(
&self,
method: &methods::broadcast_tx_commit::RpcBroadcastTxCommitRequest,
) -> MethodCallResult<
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like how I had to create a separate function for broadcast txs, but it seems like Rust does not support specialization, so I do not know if there is a better way... Any suggestions are welcome

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah there's not much you can do here besides this. The alternative is creating some traits to specialize over, but that's not gonna be great either

Copy link
Member

@ChaoticTempest ChaoticTempest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good so far and adds a lot of value to how we can debug errors in workspaces. Only a couple things I noticed we can make simpler

workspaces/src/rpc/client.rs Outdated Show resolved Hide resolved
pub(crate) async fn query_broadcast_tx(
&self,
method: &methods::broadcast_tx_commit::RpcBroadcastTxCommitRequest,
) -> MethodCallResult<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah there's not much you can do here besides this. The alternative is creating some traits to specialize over, but that's not gonna be great either

workspaces/src/rpc/client.rs Show resolved Hide resolved
Comment on lines 80 to 94
if tracing::level_enabled!(tracing::Level::DEBUG) {
tracing::error!(
target: "workspaces",
"Calling RPC method {:?} resulted in error {:?}",
method,
error
);
} else {
tracing::error!(
target: "workspaces",
"Submitting transaction with actions {:?} resulted in error {:?}",
method.signed_transaction.transaction.actions,
error
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I'm debating this, but for errors, we should be as verbose as possible anyways. There could be cases where errors are hard to reproduce

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Since errors should not happen very often and they could be hard to reproduce I think it makes sense to print them verbosely all the time.

@ChaoticTempest ChaoticTempest merged commit 7e2e106 into main Feb 11, 2022
@ChaoticTempest ChaoticTempest deleted the daniyar/workspaces-rpc-logging branch February 11, 2022 01:16
@frol frol mentioned this pull request Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants