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(abci): support tracing::span inside rs-tenderdash-abci #35

Merged
merged 9 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
4 changes: 3 additions & 1 deletion abci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description = """tenderdash-abci provides a simple framework with which to build
low-level applications on top of Tenderdash."""

[features]
default = ["server", "docker-tests", "crypto", "tcp", "unix"]
default = ["server", "docker-tests", "crypto", "tcp", "unix", "tracing-span"]
# docker-tests includes integration tests that require docker to be available
docker-tests = ["server"]
server = [
Expand All @@ -23,12 +23,14 @@ server = [
crypto = ["dep:lhash"]
tcp = ["server"]
unix = ["server"]
tracing-span = ["dep:uuid"]

[[example]]
name = "echo_socket"
required-features = ["server"]

[dependencies]
uuid = { version = "1.4.1", features = ["v4", "fast-rng"], optional = true }
tenderdash-proto = { version = "0.13.0-dev.2", path = "../proto" }
bytes = { version = "1.0" }
prost = { version = "0.11" }
Expand Down
2 changes: 2 additions & 0 deletions abci/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ pub trait RequestDispatcher {
// Implement `RequestDispatcher` for all `Application`s.
impl<A: Application> RequestDispatcher for A {
fn handle(&self, request: abci::Request) -> Option<abci::Response> {
#[cfg(feature = "tracing-span")]
let _span = super::tracing_span::span(request.clone().value?);
tracing::trace!(?request, "received request");
lklimek marked this conversation as resolved.
Show resolved Hide resolved

let response: Result<response::Value, abci::ResponseException> = match request.value? {
Expand Down
2 changes: 2 additions & 0 deletions abci/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub use tenderdash_proto as proto;

#[cfg(feature = "crypto")]
pub mod signatures;
#[cfg(feature = "tracing-span")]
mod tracing_span;

/// Errors that may happen during protobuf communication
#[derive(Debug, thiserror::Error)]
Expand Down
121 changes: 121 additions & 0 deletions abci/src/tracing_span.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use hex::ToHex;
use tenderdash_proto::abci::request::Value;
use tracing::Level;
pub(super) 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();

let span = match value {
Value::Info(r) => tracing::span!(
LEVEL,
SPAN_NAME,
endpoint,
request_id,
tenderdash_version = r.version,
block_version = r.block_version,
p2p_version = r.p2p_version,
lklimek marked this conversation as resolved.
Show resolved Hide resolved
),
Value::InitChain(r) => {
tracing::span!(
LEVEL,
SPAN_NAME,
endpoint,
request_id,
chain_id = r.chain_id
)
},
Value::PrepareProposal(r) => {
tracing::span!(
LEVEL,
SPAN_NAME,
endpoint,
request_id,
height = r.height,
round = r.round,
quorum_hash = r.quorum_hash.encode_hex::<String>(),
core_locked_height = r.core_chain_locked_height,
lklimek marked this conversation as resolved.
Show resolved Hide resolved
)
},
Value::ProcessProposal(r) => tracing::span!(
LEVEL,
SPAN_NAME,
endpoint,
request_id,
height = r.height,
round = r.round,
quorum_hash = r.quorum_hash.encode_hex::<String>(),
core_locked_height = r.core_chain_locked_height,
),
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::CheckTx(r) => {
tracing::span!(
LEVEL,
SPAN_NAME,
endpoint,
request_id,
tx = r.tx.encode_hex::<String>()
)
},
Value::Query(r) => {
tracing::span!(LEVEL, SPAN_NAME, endpoint, request_id, path = r.path)
},
_ => tracing::span!(LEVEL, SPAN_NAME, endpoint, request_id),
};

span.entered()
}
fn abci_method_name(request: &Value) -> String {
match request {
Value::ApplySnapshotChunk(_) => "ApplySnapshotChunk",
Value::CheckTx(_) => "CheckTx",
Value::Echo(_) => "Echo",
Value::ExtendVote(_) => "ExtendVote",
Value::FinalizeBlock(_) => "FinalizeBlock",
Value::Flush(_) => "Flush",
Value::Info(_) => "Info",
Value::InitChain(_) => "InitChain",
Value::ListSnapshots(_) => "ListSnapshots",
Value::LoadSnapshotChunk(_) => "LoadSnapshotChunk",
Value::OfferSnapshot(_) => "OfferSnapshot",
Value::PrepareProposal(_) => "PrepareProposal",
Value::ProcessProposal(_) => "ProcessProposal",
Value::Query(_) => "Query",
Value::VerifyVoteExtension(_) => "VerifyVoteExtension",
}
.to_string()
}
1 change: 1 addition & 0 deletions proto-compiler/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub static CUSTOM_TYPE_ATTRIBUTES: &[(&str, &str)] = &[
(".tendermint.types.TxProof", SERIALIZED),
(".tendermint.crypto.Proof", SERIALIZED),
(".tendermint.abci.Response.value", DERIVE_FROM),
(".tendermint.abci.Request.value", DERIVE_FROM),
];

/// Custom field attributes applied on top of protobuf fields in (a) struct(s)
Expand Down