Skip to content

Commit

Permalink
feat: add otlp tracing
Browse files Browse the repository at this point in the history
snapshot andy's work
  • Loading branch information
alex-miao authored and andysim3d committed Feb 21, 2025
1 parent e96738d commit 2a978da
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 5 deletions.
120 changes: 120 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions bin/rundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ metrics-derive.workspace = true
metrics-exporter-prometheus = { version = "0.16.2", default-features = false, features = ["http-listener"] }
metrics-process = "2.4.0"
metrics-util = "0.19.0"
opentelemetry = "0.28.0"
opentelemetry-otlp = { version = "0.28.0", features = ["grpc-tonic"] }
opentelemetry_sdk = "0.28.0"
paste = "1.0"
reth-tasks.workspace = true
serde.workspace = true
Expand All @@ -49,7 +52,10 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal", "
tokio-metrics = "0.4.0"
tokio-rustls = "0.26.0"
tokio-util.workspace = true
tonic.workspace = true
tracing.workspace = true
tracing-appender = "0.2.3"
tracing-log = "0.2.0"
tracing-opentelemetry = "0.29.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "fmt", "json"] }
opentelemetry-stdout = "0.28.0"
2 changes: 2 additions & 0 deletions bin/rundler/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use rundler_types::{
/// Listens for a ctrl-c signal and shuts down all components when received.
pub async fn run() -> anyhow::Result<()> {
let opt = Cli::parse();
// let tracer = tracing::init_tracer();
let _guard = tracing::configure_logging(&opt.logs)?;
tracing::info!("Parsed CLI options: {:#?}", opt);

Expand Down Expand Up @@ -133,6 +134,7 @@ pub async fn run() -> anyhow::Result<()> {
task_manager.graceful_shutdown_with_timeout(Duration::from_secs(10));

tracing::info!("Shutdown, goodbye");
// tracer.shutdown()?;
Ok(())
}

Expand Down
31 changes: 28 additions & 3 deletions bin/rundler/src/cli/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
// You should have received a copy of the GNU General Public License along with Rundler.
// If not, see https://www.gnu.org/licenses/.

use std::io;
use std::{io, time::Duration};

use opentelemetry::{global, trace::TracerProvider};
use opentelemetry_otlp::{WithExportConfig, WithTonicConfig};
use opentelemetry_sdk::Resource;
use tonic::metadata::MetadataMap;
pub use tracing::*;
use tracing::{subscriber, subscriber::Interest, Metadata, Subscriber};
use tracing_appender::non_blocking::WorkerGuard;
use tracing_log::LogTracer;
use tracing_opentelemetry::OpenTelemetryLayer;
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, FmtSubscriber, Layer};

use super::LogsArgs;
Expand All @@ -28,15 +33,36 @@ pub fn configure_logging(config: &LogsArgs) -> anyhow::Result<WorkerGuard> {
tracing_appender::non_blocking(io::stdout())
};

let metadata = MetadataMap::new();

// let exporter = opentelemetry_otlp::SpanExporter::builder()
// .with_http()
// .with_endpoint("http://127.0.0.1:4318")
// .with_protocol(opentelemetry_otlp::Protocol::HttpBinary)
// .with_timeout(Duration::from_secs(3))
// // .with_metadata(metadata)
// .build()?;
let exporter = opentelemetry_stdout::SpanExporter::default();
let tracer_provider = opentelemetry_sdk::trace::SdkTracerProvider::builder()
.with_batch_exporter(exporter)
.with_resource(Resource::builder().with_service_name("rundler").build())
.build();

global::set_tracer_provider(tracer_provider.clone());
let tracer = tracer_provider.tracer("rundler-tracer");
let otel_layer = OpenTelemetryLayer::new(tracer);

let subscriber_builder = FmtSubscriber::builder()
.with_env_filter(EnvFilter::from_default_env())
.with_writer(appender);

if config.json {
subscriber::set_global_default(
subscriber_builder
.json()
.finish()
.with(TargetBlacklistLayer),
.with(TargetBlacklistLayer)
.with(otel_layer),
)?;
} else {
subscriber::set_global_default(
Expand All @@ -47,7 +73,6 @@ pub fn configure_logging(config: &LogsArgs) -> anyhow::Result<WorkerGuard> {
)?;
}

// Redirect logs from external crates using `log` to the tracing subscriber
LogTracer::init()?;

Ok(guard)
Expand Down
10 changes: 8 additions & 2 deletions crates/rpc/src/rundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use async_trait::async_trait;
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use rundler_sim::{gas, FeeEstimator};
use rundler_types::{chain::ChainSpec, pool::Pool, UserOperation, UserOperationVariant};
use tracing::{info, info_span};

use crate::{
eth::{EntryPointRouter, EthResult, EthRpcError},
Expand Down Expand Up @@ -70,9 +71,11 @@ where
F: FeeEstimator + 'static,
{
async fn max_priority_fee_per_gas(&self) -> RpcResult<U128> {
let span = info_span!("max_priority_fee_per_gas api");
let x = span.in_scope(|| self);
utils::safe_call_rpc_handler(
"rundler_maxPriorityFeePerGas",
RundlerApi::max_priority_fee_per_gas(self),
RundlerApi::max_priority_fee_per_gas(x),
)
.await
}
Expand Down Expand Up @@ -110,9 +113,12 @@ where
}

async fn max_priority_fee_per_gas(&self) -> EthResult<U128> {
let span = info_span!("max_priority_fee_per_gas impl");
let x = span.in_scope(|| None);
info!("here is a log");
let (bundle_fees, _) = self
.fee_estimator
.required_bundle_fees(None)
.required_bundle_fees(x)
.await
.context("should get required fees")?;
Ok(U128::from(
Expand Down
3 changes: 3 additions & 0 deletions crates/sim/src/gas/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rundler_provider::{BlockHashOrNumber, DAGasProvider, EvmProvider};
use rundler_types::{chain::ChainSpec, da::DAGasUOData, GasFees, UserOperation};
use rundler_utils::math;
use tokio::try_join;
use tracing::info_span;

use super::oracle::FeeOracle;

Expand Down Expand Up @@ -218,6 +219,8 @@ impl<P: EvmProvider, O: FeeOracle> FeeEstimator for FeeEstimatorImpl<P, O> {
&self,
min_fees: Option<GasFees>,
) -> anyhow::Result<(GasFees, u128)> {
let span = info_span!("max_priority_fee_per_gas innner ");

let (base_fee, priority_fee) =
try_join!(self.get_pending_base_fee(), self.get_priority_fee())?;

Expand Down

0 comments on commit 2a978da

Please sign in to comment.