reth_node_core/args/
trace.rs1use clap::Parser;
4use eyre::WrapErr;
5use reth_tracing::tracing_subscriber::EnvFilter;
6use reth_tracing_otlp::OtlpProtocol;
7use url::Url;
8
9#[derive(Debug, Clone, Parser)]
11pub struct TraceArgs {
12    #[arg(
20        long = "tracing-otlp",
21        env = "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
23        global = true,
24        value_name = "URL",
25        num_args = 0..=1,
26        default_missing_value = "http://localhost:4318/v1/traces",
27        require_equals = true,
28        value_parser = parse_otlp_endpoint,
29        help_heading = "Tracing"
30    )]
31    pub otlp: Option<Url>,
32
33    #[arg(
40        long = "tracing-otlp-protocol",
41        env = "OTEL_EXPORTER_OTLP_PROTOCOL",
42        global = true,
43        value_name = "PROTOCOL",
44        default_value = "http",
45        help_heading = "Tracing"
46    )]
47    pub protocol: OtlpProtocol,
48
49    #[arg(
57        long = "tracing-otlp.filter",
58        global = true,
59        value_name = "FILTER",
60        default_value = "debug",
61        help_heading = "Tracing"
62    )]
63    pub otlp_filter: EnvFilter,
64}
65
66impl Default for TraceArgs {
67    fn default() -> Self {
68        Self {
69            otlp: None,
70            protocol: OtlpProtocol::Http,
71            otlp_filter: EnvFilter::from_default_env(),
72        }
73    }
74}
75
76impl TraceArgs {
77    pub fn validate(&mut self) -> eyre::Result<()> {
79        if let Some(url) = &mut self.otlp {
80            self.protocol.validate_endpoint(url)?;
81        }
82        Ok(())
83    }
84}
85
86fn parse_otlp_endpoint(arg: &str) -> eyre::Result<Url> {
88    Url::parse(arg).wrap_err("Invalid URL for OTLP trace output")
89}