Skip to content

Commit

Permalink
lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirko-von-Leipzig committed Feb 5, 2025
1 parent ddc6e3f commit 2497c1e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

32 changes: 16 additions & 16 deletions crates/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ workspace = true
vergen = ["dep:vergen", "dep:vergen-gitcl"]

[dependencies]
anyhow = { version = "1.0" }
figment = { version = "0.10", features = ["env", "toml"] }
http = "1.2"
itertools = { workspace = true }
miden-objects = { workspace = true }
opentelemetry = "0.27"
opentelemetry-otlp = { version = "0.27", features = ["tls-roots"] }
opentelemetry_sdk = { version = "0.27", features = ["rt-tokio"] }
rand = { workspace = true }
serde = { version = "1.0", features = ["derive"] }
thiserror = { workspace = true }
tonic = { workspace = true }
tracing = { workspace = true }
tracing-forest = { version = "0.1", optional = true, features = ["chrono"] }
tracing-opentelemetry = "0.28"
tracing-subscriber = { workspace = true }
anyhow = { version = "1.0" }
figment = { version = "0.10", features = ["env", "toml"] }
http = "1.2"
itertools = { workspace = true }
miden-objects = { workspace = true }
opentelemetry = "0.27"
opentelemetry-otlp = { version = "0.27", features = ["tls-roots"] }
opentelemetry_sdk = { version = "0.27", features = ["rt-tokio"] }
rand = { workspace = true }
serde = { version = "1.0", features = ["derive"] }
thiserror = { workspace = true }
tonic = { workspace = true }
tracing = { workspace = true }
tracing-forest = { version = "0.1", optional = true, features = ["chrono"] }
tracing-opentelemetry = "0.28"
tracing-subscriber = { workspace = true }
# Optional dependencies enabled by `vergen` feature.
# This must match the version expected by `vergen-gitcl`.
vergen = { "version" = "9.0", optional = true }
Expand Down
28 changes: 12 additions & 16 deletions crates/utils/src/tracing/grpc.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
use tracing_opentelemetry::OpenTelemetrySpanExt;

/// A [trace_fn] implementation for the block producer which adds open-telemetry information to the
/// span.
/// A [`trace_fn`](tonic::transport::server::Server) implementation for the block producer which
/// adds open-telemetry information to the span.
///
/// Creates an `info` span following the open-telemetry standard: `block-producer.rpc/{method}`.
/// Additionally also pulls in remote tracing context which allows the server trace to be connected
/// to the client's origin trace.
///
/// [trace_fn]: tonic::transport::server::Server::trace_fn
pub fn block_producer_trace_fn(request: &http::Request<()>) -> tracing::Span {
let span = match request.uri().path().rsplit('/').next() {
Some("SubmitProvenTransaction") => {
tracing::info_span!("block-producer.rpc/SubmitProvenTransaction")
},
_ => tracing::info_span!("block-producer.rpc/Unknown"),
let span = if let Some("SubmitProvenTransaction") = request.uri().path().rsplit('/').next() {
tracing::info_span!("block-producer.rpc/SubmitProvenTransaction")
} else {
tracing::info_span!("block-producer.rpc/Unknown")
};

add_otel_span_attributes(span, request)
}

/// A [trace_fn] implementation for the store which adds open-telemetry information to the span.
/// A [`trace_fn`](tonic::transport::server::Server) implementation for the store which adds
/// open-telemetry information to the span.
///
/// Creates an `info` span following the open-telemetry standard: `store.rpc/{method}`. Additionally
/// also pulls in remote tracing context which allows the server trace to be connected to the
/// client's origin trace.
///
/// [trace_fn]: tonic::transport::server::Server::trace_fn
pub fn store_trace_fn(request: &http::Request<()>) -> tracing::Span {
let span = match request.uri().path().rsplit('/').next() {
Some("ApplyBlock") => tracing::info_span!("store.rpc/ApplyBlock"),
Expand Down Expand Up @@ -79,7 +75,7 @@ impl tonic::service::Interceptor for OtelInterceptor {
) -> Result<tonic::Request<()>, tonic::Status> {
let ctx = tracing::Span::current().context();
opentelemetry::global::get_text_map_propagator(|propagator| {
propagator.inject_context(&ctx, &mut MetadataInjector(request.metadata_mut()))
propagator.inject_context(&ctx, &mut MetadataInjector(request.metadata_mut()));
});

Ok(request)
Expand All @@ -88,13 +84,13 @@ impl tonic::service::Interceptor for OtelInterceptor {

struct MetadataExtractor<'a>(&'a tonic::metadata::MetadataMap);
impl opentelemetry::propagation::Extractor for MetadataExtractor<'_> {
/// Get a value for a key from the MetadataMap. If the value can't be converted to &str,
/// Get a value for a key from the `MetadataMap`. If the value can't be converted to &str,
/// returns None
fn get(&self, key: &str) -> Option<&str> {
self.0.get(key).and_then(|metadata| metadata.to_str().ok())
}

/// Collect all the keys from the MetadataMap.
/// Collect all the keys from the `MetadataMap`.
fn keys(&self) -> Vec<&str> {
self.0
.keys()
Expand All @@ -108,7 +104,7 @@ impl opentelemetry::propagation::Extractor for MetadataExtractor<'_> {

struct MetadataInjector<'a>(&'a mut tonic::metadata::MetadataMap);
impl opentelemetry::propagation::Injector for MetadataInjector<'_> {
/// Set a key and value in the MetadataMap. Does nothing if the key or value are not valid
/// Set a key and value in the `MetadataMap`. Does nothing if the key or value are not valid
/// inputs
fn set(&mut self, key: &str, value: String) {
if let Ok(key) = tonic::metadata::MetadataKey::from_bytes(key.as_bytes()) {
Expand Down

0 comments on commit 2497c1e

Please sign in to comment.