mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
Improve tracing (#5698)
* Improve tracing implementation * Enable tracing in runtime interfaces * Switch to `TRACE` level
This commit is contained in:
@@ -19,3 +19,4 @@ sp-runtime-interface-test-wasm-deprecated = { version = "2.0.0-dev", path = "../
|
||||
sp-state-machine = { version = "0.8.0-dev", path = "../../../primitives/state-machine" }
|
||||
sp-runtime = { version = "2.0.0-dev", path = "../../runtime" }
|
||||
sp-io = { version = "2.0.0-dev", path = "../../io" }
|
||||
tracing = "0.1.13"
|
||||
|
||||
@@ -27,6 +27,8 @@ use sp_runtime_interface_test_wasm_deprecated::WASM_BINARY as WASM_BINARY_DEPREC
|
||||
use sp_wasm_interface::HostFunctions as HostFunctionsT;
|
||||
use sc_executor::CallInWasm;
|
||||
|
||||
use std::{collections::HashSet, sync::{Arc, Mutex}};
|
||||
|
||||
type TestExternalities = sp_state_machine::TestExternalities<sp_runtime::traits::BlakeTwo256, u64>;
|
||||
|
||||
fn call_wasm_method<HF: HostFunctionsT>(binary: &[u8], method: &str) -> TestExternalities {
|
||||
@@ -150,3 +152,47 @@ fn test_versionining_with_new_host_works() {
|
||||
"test_versionning_works",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tracing() {
|
||||
use tracing::span::Id as SpanId;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct TracingSubscriber(Arc<Mutex<Inner>>);
|
||||
|
||||
#[derive(Default)]
|
||||
struct Inner {
|
||||
spans: HashSet<&'static str>,
|
||||
}
|
||||
|
||||
impl tracing::subscriber::Subscriber for TracingSubscriber {
|
||||
fn enabled(&self, _: &tracing::Metadata) -> bool { true }
|
||||
|
||||
fn new_span(&self, span: &tracing::span::Attributes) -> tracing::Id {
|
||||
let mut inner = self.0.lock().unwrap();
|
||||
let id = SpanId::from_u64((inner.spans.len() + 1) as _);
|
||||
inner.spans.insert(span.metadata().name());
|
||||
id
|
||||
}
|
||||
|
||||
fn record(&self, _: &SpanId, _: &tracing::span::Record) {}
|
||||
|
||||
fn record_follows_from(&self, _: &SpanId, _: &SpanId) {}
|
||||
|
||||
fn event(&self, _: &tracing::Event) {}
|
||||
|
||||
fn enter(&self, _: &SpanId) {}
|
||||
|
||||
fn exit(&self, _: &SpanId) {}
|
||||
}
|
||||
|
||||
let subscriber = TracingSubscriber(Default::default());
|
||||
let _guard = tracing::subscriber::set_default(subscriber.clone());
|
||||
|
||||
// Call some method to generate a trace
|
||||
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_return_data");
|
||||
|
||||
let inner = subscriber.0.lock().unwrap();
|
||||
assert!(inner.spans.contains("return_input_version_1"));
|
||||
assert!(inner.spans.contains("ext_test_api_return_input_version_1"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user