Skip to content

Commit

Permalink
Improve tracing (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jontes-Tech authored Aug 7, 2024
1 parent 0f05543 commit 6a9ef2c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
22 changes: 20 additions & 2 deletions server/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use axum::extract::MatchedPath;
use axum::http::Request;
use axum::response::{Html, Redirect};
use std::{net::SocketAddr, sync::Arc};

Expand All @@ -6,7 +8,7 @@ use tokio::net::TcpListener;
use tokio_util::sync::CancellationToken;
use tower_http::cors::CorsLayer;
use tower_http::trace::TraceLayer;
use tracing::info;
use tracing::{info, info_span};

use crate::routes;
use crate::state::AppState;
Expand Down Expand Up @@ -77,7 +79,23 @@ pub fn setup(state: AppState) -> App {
.route("/metrics", get(metrics::handle))
.fallback(routes::four_oh_four::handler)
.layer(CorsLayer::permissive())
.layer(TraceLayer::new_for_http())
.layer(
TraceLayer::new_for_http().make_span_with(|request: &Request<_>| {
// Log the matched route's path (with placeholders not filled in).
// Use request.uri() or OriginalUri if you want the real path.
let matched_path = request
.extensions()
.get::<MatchedPath>()
.map(MatchedPath::as_str);

info_span!(
"http_request",
method = ?request.method(),
matched_path,
some_other_field = tracing::field::Empty,
)
}),
)
.with_state(Arc::new(state));

App { router }
Expand Down
12 changes: 8 additions & 4 deletions shared/src/core/resolvers/universal.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use std::vec;

use ethers::prelude::ProviderError::JsonRpcClientError;
use ethers::{
providers::namehash,
types::{Address, Bytes, transaction::eip2718::TypedTransaction},
types::{transaction::eip2718::TypedTransaction, Address, Bytes},
};
use ethers::prelude::ProviderError::JsonRpcClientError;
use ethers_ccip_read::{CCIPReadMiddlewareError, CCIPRequest};
use ethers_core::abi;
use ethers_core::abi::{ParamType, Token};
use ethers_core::types::H160;
use hex_literal::hex;
use lazy_static::lazy_static;
use tracing::instrument;
use tracing::{instrument, span};

use crate::core::CCIPProvider;
use crate::core::error::ProfileError;
use crate::core::CCIPProvider;
use crate::models::lookup::ENSLookup;
use crate::utils::dns::dns_encode;
use crate::utils::vec::dedup_ord;
Expand Down Expand Up @@ -66,6 +66,8 @@ pub async fn resolve_universal(
typed_transaction.set_to(*universal_resolver);
typed_transaction.set_data(Bytes::from(transaction_data));

let span = span!(tracing::Level::INFO, "ccip_call", name = name);

// Call the transaction
let (res, ccip_requests) =
provider
Expand All @@ -88,6 +90,8 @@ pub async fn resolve_universal(
ProfileError::RPCError(provider_error)
})?;

drop(span);

// Abi Decode
let result = abi::decode(
&[
Expand Down

0 comments on commit 6a9ef2c

Please sign in to comment.