Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ snap = '1'
sp1-helper = '6.1.0'
sp1-sdk = '6.1.0'
sp1-zkvm = { version = '6.1.0' }
sse-stream = '0.2'
static_assertions = '1'
strum = { version = '0.28', features = ['derive'] }
syn = { version = '2', features = ['full'] }
Expand Down
2 changes: 1 addition & 1 deletion ad_hoc_bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ fn main() -> Result<()> {
.tempdir()?
.keep();

binary_utils::initialize_tracing_logger(module_path!(), Some(&data_dir), None, false)?;
binary_utils::initialize_tracing_logger(module_path!(), Some(&data_dir), None, false, true)?;
binary_utils::initialize_rayon()?;
#[cfg(not(target_os = "windows"))]
print_jemalloc_stats()?;
Expand Down
94 changes: 90 additions & 4 deletions binary_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use chrono::{Local, SecondsFormat};
use core::{error::Error, fmt::Debug};
use fs_err as fs;
use logging::{debug_with_peers, exception};
use logroller::{Compression, LogRollerBuilder, Rotation, RotationSize};
Expand All @@ -12,20 +13,28 @@ use std::{
sync::{Arc, OnceLock},
};
use tokio::runtime::Runtime;
use tracing::Level;
use tracing::{
Level,
field::{Field, Visit},
};
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::{
EnvFilter, Registry,
field::{MakeVisitor as _, RecordFields, VisitOutput as _},
filter::LevelFilter,
fmt::{self, format::Writer, time::FormatTime},
fmt::{
self,
format::{DefaultFields, DefaultVisitor, FormatFields, Writer},
time::FormatTime,
},
prelude::*,
reload::{self, Handle},
};
use types::redacting_url::RedactingUrl;

static LOG_GUARD: OnceLock<WorkerGuard> = OnceLock::new();

#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct TelemetryConfig {
pub url: RedactingUrl,
pub service_name: String,
Expand Down Expand Up @@ -80,6 +89,7 @@ pub fn initialize_tracing_logger(
data_dir: Option<&Path>,
telemetry_config: Option<TelemetryConfig>,
always_write_style: bool,
with_peers: bool,
) -> Result<TracingHandle> {
let mut filter = EnvFilter::default()
.add_directive(LevelFilter::OFF.into())
Expand Down Expand Up @@ -132,6 +142,7 @@ pub fn initialize_tracing_logger(
let enable_ansi = always_write_style || io::stdout().is_terminal();

let stdout_layer = fmt::layer::<Registry>()
.fmt_fields(Fields { with_peers })
.compact()
.with_thread_ids(false)
.with_target(true)
Expand Down Expand Up @@ -256,6 +267,7 @@ pub fn initialize_tracing_logger(
.add_directive("exception=error".parse()?);

let file_layer = fmt::layer()
.fmt_fields(Fields { with_peers })
.compact()
.with_ansi(false)
.with_writer(non_blocking)
Expand Down Expand Up @@ -313,6 +325,80 @@ pub fn initialize_rayon() -> Result<()> {
.map_err(Into::into)
}

/// The default field format, minus the peer counts of a process without a network.
struct Fields {
with_peers: bool,
}

impl<'writer> FormatFields<'writer> for Fields {
fn format_fields<R: RecordFields>(
&self,
writer: Writer<'writer>,
fields: R,
) -> core::fmt::Result {
let mut visitor = DefaultFields::new().make_visitor(writer);

if self.with_peers {
fields.record(&mut visitor);
} else {
fields.record(&mut WithoutPeers(&mut visitor));
}

visitor.finish()
}
}

// The `*_with_peers!` macros always add a `peers` field, and `tracing` offers no way to drop a
// field short of the visitor that writes it. The validator client has no peers to report.
struct WithoutPeers<'visitor, 'writer>(&'visitor mut DefaultVisitor<'writer>);

// Forwards every method, not only the ones `DefaultVisitor` overrides today, so a future
// override in `tracing-subscriber` is not silently bypassed here.
impl Visit for WithoutPeers<'_, '_> {
fn record_f64(&mut self, field: &Field, value: f64) {
self.0.record_f64(field, value);
}

fn record_i64(&mut self, field: &Field, value: i64) {
self.0.record_i64(field, value);
}

fn record_u64(&mut self, field: &Field, value: u64) {
self.0.record_u64(field, value);
}

fn record_i128(&mut self, field: &Field, value: i128) {
self.0.record_i128(field, value);
}

fn record_u128(&mut self, field: &Field, value: u128) {
self.0.record_u128(field, value);
}

fn record_bool(&mut self, field: &Field, value: bool) {
self.0.record_bool(field, value);
}

fn record_str(&mut self, field: &Field, value: &str) {
self.0.record_str(field, value);
}

fn record_bytes(&mut self, field: &Field, value: &[u8]) {
self.0.record_bytes(field, value);
}

fn record_error(&mut self, field: &Field, value: &(dyn Error + 'static)) {
self.0.record_error(field, value);
}

fn record_debug(&mut self, field: &Field, value: &dyn Debug) {
// The macros record the counts through `Display`, which arrives here.
if field.name() != "peers" {
self.0.record_debug(field, value);
}
}
}

#[cfg(test)]
mod tests {
use std::sync::{LazyLock, Mutex};
Expand All @@ -334,7 +420,7 @@ mod tests {
let mut lock = LOGGER.lock().expect("Failed to acquire LOGGER mutex lock");
if lock.is_none() {
let handle =
initialize_tracing_logger(module_path!(), Some(data_dir.path()), None, false)
initialize_tracing_logger(module_path!(), Some(data_dir.path()), None, false, true)
.expect("Failed to initialize tracing logger");

*lock = Some(LoggerWithTempDir {
Expand Down
18 changes: 10 additions & 8 deletions bindings/c/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{
alloc::{self, Layout},
ffi::{CStr, CString, c_char, c_void},
ffi::{CStr, CString, OsString, c_char, c_void},
};

use allocator as _;
use anyhow::{Context, Result, bail};
use clap::{Error as ClapError, Parser};
use clap::Error as ClapError;
use eth1_api::ClientVersionV1;
use execution_engine::{
BlobAndProofV1, EngineGetPayloadV1Response, EngineGetPayloadV2Response,
Expand Down Expand Up @@ -515,13 +515,15 @@ pub extern "C" fn grandine_shutdown() {
#[unsafe(no_mangle)]
pub unsafe extern "C" fn grandine_run(argc: u64, argv: *const *const c_char) -> u64 {
unsafe fn try_run(argc: u64, argv: *const *const c_char) -> Result<()> {
let args = std::iter::once("").chain(unsafe {
std::slice::from_raw_parts(argv, argc as usize)
.into_iter()
.filter_map(|it| CStr::from_ptr(*it).to_str().ok())
});
let args = std::iter::once("")
.chain(unsafe {
std::slice::from_raw_parts(argv, argc as usize)
.into_iter()
.filter_map(|it| CStr::from_ptr(*it).to_str().ok())
})
.map(OsString::from);

let args = GrandineArgs::try_parse_from(args)?;
let args = GrandineArgs::parse_strictly(args)?;

run(args)
}
Expand Down
Loading
Loading