Skip to content

Commit

Permalink
Fix/rust log filtering (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv authored Nov 27, 2024
1 parent 830e95e commit de271ba
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- fix(tracing): RUST_LOG filtering support
- fix(fgw): fetch class
- feat: possibility of starting madara & kakarot-rpc in docker
- feat(debug): service cancelling and profiling build
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ Madara comes packed with OTEL integration, supporting export of traces, metrics
### Basic Command-Line Option
- **`--analytics-collection-endpoint <URL>`**: Endpoint for OTLP collector, if not provided then OTLP is not enabled.
- **`--analytics-log-level <Log Level>`**: Picked up from `RUST_LOG` automatically, can be provided using this flag as well.
- **`--analytics-service-name <Name>`**: Allows to customize the collection service name.
#### Setting up Signoz
Expand Down
14 changes: 5 additions & 9 deletions crates/client/analytics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,27 @@ use tracing::Level;
use tracing_opentelemetry::OpenTelemetryLayer;
use tracing_subscriber::layer::SubscriberExt as _;
use tracing_subscriber::util::SubscriberInitExt as _;
use tracing_subscriber::EnvFilter;
use url::Url;

pub struct Analytics {
meter_provider: Option<SdkMeterProvider>,
service_name: String,
log_level: Level,
collection_endpoint: Option<Url>,
}

impl Analytics {
pub fn new(
service_name: String,
log_level: tracing::Level,
collection_endpoint: Option<Url>,
) -> anyhow::Result<Self> {
Ok(Self { meter_provider: None, service_name, log_level, collection_endpoint })
pub fn new(service_name: String, collection_endpoint: Option<Url>) -> anyhow::Result<Self> {
Ok(Self { meter_provider: None, service_name, collection_endpoint })
}

pub fn setup(&mut self) -> anyhow::Result<()> {
let local_offset = UtcOffset::current_local_offset().unwrap_or(UtcOffset::UTC);
let custom_formatter = CustomFormatter { local_offset };

let tracing_subscriber = tracing_subscriber::registry()
.with(tracing_subscriber::filter::LevelFilter::from_level(self.log_level))
.with(tracing_subscriber::fmt::layer().event_format(custom_formatter));
.with(tracing_subscriber::fmt::layer().event_format(custom_formatter))
.with(EnvFilter::from_default_env());

if self.collection_endpoint.is_none() {
tracing_subscriber.init();
Expand Down
5 changes: 0 additions & 5 deletions crates/node/src/cli/analytics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use clap::Args;
use mp_utils::parsers::parse_url;
use tracing::Level;
use url::Url;

/// Parameters used to config analytics.
Expand All @@ -10,10 +9,6 @@ pub struct AnalyticsParams {
#[arg(env = "MADARA_ANALYTICS_SERVICE_NAME", long, alias = "analytics", default_value = "madara_analytics")]
pub analytics_service_name: String,

/// Log level of the service.
#[arg(env = "RUST_LOG", long, default_value = "info")]
pub analytics_log_level: Level,

/// Endpoint of the analytics server.
#[arg(env = "OTEL_EXPORTER_OTLP_ENDPOINT", long, value_parser = parse_url, default_value = None)]
pub analytics_collection_endpoint: Option<Url>,
Expand Down
1 change: 0 additions & 1 deletion crates/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ async fn main() -> anyhow::Result<()> {

let mut analytics = Analytics::new(
run_cmd.analytics_params.analytics_service_name.clone(),
run_cmd.analytics_params.analytics_log_level,
run_cmd.analytics_params.analytics_collection_endpoint.clone(),
)
.context("Initializing analytics service")?;
Expand Down

0 comments on commit de271ba

Please sign in to comment.