Skip to content

Commit

Permalink
chore: minor improvements and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Sep 8, 2023
1 parent bdbe283 commit 8de550d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 52 deletions.
1 change: 0 additions & 1 deletion abci/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ impl<A: Application> RequestDispatcher for A {
}
.unwrap_or_else(|e| e.into());

// TODO: errors as err
if let response::Value::Exception(ref exception) = response {
tracing::error!(response=?exception, "sending ABCI exception");
} else {
Expand Down
3 changes: 2 additions & 1 deletion abci/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub use tenderdash_proto as proto;
#[cfg(feature = "crypto")]
pub mod signatures;
#[cfg(feature = "tracing-span")]
mod tracing_span;
/// Create tracing::Span for better logging
pub mod tracing_span;

/// Errors that may happen during protobuf communication
#[derive(Debug, thiserror::Error)]
Expand Down
97 changes: 47 additions & 50 deletions abci/src/tracing_span.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
use tenderdash_proto::abci::request::Value;
use tracing::Level;

const SPAN_NAME: &str = "abci";
const LEVEL: Level = Level::ERROR;

macro_rules! block_span {
($request: expr, $endpoint:expr, $request_id:expr) => {
tracing::span!(
LEVEL,
SPAN_NAME,
endpoint = $endpoint,
request_id = $request_id,
height = $request.height,
round = $request.round
)
};
}
/// Creates a new span for tracing.
///
/// This function creates a new `tracing::span::EnteredSpan` based on the
/// provided request. It uses the request to determine the endpoint and includes
/// a unique request ID in the span.
///
/// The level of the span is set to ERROR, so it will be included on all log
/// levels.
///
/// # Arguments
///
/// * `request` - A value that can be converted into a `Value`. Depending on the
/// specific variant of `Value`, additional information like height, round, or
/// path might be included in the span.
///
/// # Returns
///
/// An entered span which represents an active or entered span state.
///
/// # Examples
///
/// ```
/// let request = Value::Info(RequestInfo::new());
/// let span = span(request);
/// ```
pub fn span<T>(request: T) -> tracing::span::EnteredSpan
where
T: Into<Value>,
{
let value = request.into();
const SPAN_NAME: &str = "abci";
const LEVEL: Level = Level::ERROR;

let endpoint = abci_method_name(&value);
let request_id = uuid::Uuid::new_v4().to_string();

Expand All @@ -16,54 +55,11 @@ where
Value::InitChain(_r) => {
tracing::span!(LEVEL, SPAN_NAME, endpoint, request_id)
},
Value::PrepareProposal(r) => {
tracing::span!(
LEVEL,
SPAN_NAME,
endpoint,
request_id,
height = r.height,
round = r.round,
)
},
Value::ProcessProposal(r) => tracing::span!(
LEVEL,
SPAN_NAME,
endpoint,
request_id,
height = r.height,
round = r.round,
),
Value::ExtendVote(r) => {
tracing::span!(
LEVEL,
SPAN_NAME,
endpoint,
request_id,
height = r.height,
round = r.round
)
},
Value::VerifyVoteExtension(r) => {
tracing::span!(
LEVEL,
SPAN_NAME,
endpoint,
request_id,
height = r.height,
round = r.round
)
},
Value::FinalizeBlock(r) => {
tracing::span!(
LEVEL,
SPAN_NAME,
endpoint,
request_id,
height = r.height,
round = r.round
)
},
Value::PrepareProposal(r) => block_span!(r, endpoint, request_id),
Value::ProcessProposal(r) => block_span!(r, endpoint, request_id),
Value::ExtendVote(r) => block_span!(r, endpoint, request_id),
Value::VerifyVoteExtension(r) => block_span!(r, endpoint, request_id),
Value::FinalizeBlock(r) => block_span!(r, endpoint, request_id),
Value::CheckTx(_r) => {
tracing::span!(LEVEL, SPAN_NAME, endpoint, request_id)
},
Expand All @@ -75,6 +71,7 @@ where

span.entered()
}

fn abci_method_name(request: &Value) -> String {
match request {
Value::ApplySnapshotChunk(_) => "ApplySnapshotChunk",
Expand Down

0 comments on commit 8de550d

Please sign in to comment.