fix(air-interpreter): enable multiple invoke_tracing calls for air-interpreter (#753)

This commit is contained in:
raftedproc 2023-11-08 15:00:56 +03:00 committed by GitHub
parent 1b7de5e659
commit 938e5eb033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 16 deletions

View File

@ -32,18 +32,6 @@ pub fn init_logger(default_level: Option<LevelFilter>) {
}
#[allow(dead_code)]
// TODO it worth moving it to marine_rs_sdk
pub fn init_tracing(tracing_params: String, trace_mode: u8) {
use tracing_subscriber::fmt::format::FmtSpan;
let builder = tracing_subscriber::fmt()
.with_env_filter(tracing_params)
.with_span_events(FmtSpan::ENTER | FmtSpan::CLOSE)
.with_writer(std::io::stderr);
if trace_mode == 0 {
builder.json().init();
} else {
// Human-readable output.
builder.init();
}
pub fn json_output_mode(trace_mode: u8) -> bool {
trace_mode == 0
}

View File

@ -63,8 +63,23 @@ pub fn invoke_tracing(
tracing_params: String,
tracing_output_mode: u8,
) -> InterpreterOutcome {
logger::init_tracing(tracing_params, tracing_output_mode);
execute_air(air, prev_data, data, params, call_results)
use tracing::Dispatch;
use tracing_subscriber::fmt::format::FmtSpan;
let builder = tracing_subscriber::fmt()
.with_env_filter(tracing_params)
.with_span_events(FmtSpan::ENTER | FmtSpan::CLOSE)
.with_writer(std::io::stderr);
let dispatch = if logger::json_output_mode(tracing_output_mode) {
let subscriber = builder.json().finish();
Dispatch::new(subscriber)
} else {
// Human-readable output.
let subscriber = builder.finish();
Dispatch::new(subscriber)
};
tracing::dispatcher::with_default(&dispatch, || execute_air(air, prev_data, data, params, call_results))
}
#[marine]