Rework telemetry to replace the use of tracing with an object we pass around (#8143)

polkadot companion: paritytech/polkadot#2535
This commit is contained in:
Cecile Tonglet
2021-03-11 11:05:45 +01:00
committed by GitHub
parent 7aaba0c154
commit 8031b6eacb
55 changed files with 1028 additions and 838 deletions
+1 -35
View File
@@ -24,7 +24,7 @@
//!
//! See `sp-tracing` for examples on how to use tracing.
//!
//! Currently we provide `Log` (default), `Telemetry` variants for `Receiver`
//! Currently we only provide `Log` (default).
#![warn(missing_docs)]
@@ -46,7 +46,6 @@ use tracing_subscriber::{
CurrentSpan,
layer::{Layer, Context},
};
use sc_telemetry::{telemetry, SUBSTRATE_INFO};
use sp_tracing::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER};
#[doc(hidden)]
@@ -67,8 +66,6 @@ pub struct ProfilingLayer {
pub enum TracingReceiver {
/// Output to logger
Log,
/// Output to telemetry
Telemetry,
}
impl Default for TracingReceiver {
@@ -214,10 +211,6 @@ impl ProfilingLayer {
pub fn new(receiver: TracingReceiver, targets: &str) -> Self {
match receiver {
TracingReceiver::Log => Self::new_with_handler(Box::new(LogTraceHandler), targets),
TracingReceiver::Telemetry => Self::new_with_handler(
Box::new(TelemetryTraceHandler),
targets,
),
}
}
@@ -392,33 +385,6 @@ impl TraceHandler for LogTraceHandler {
}
}
/// TraceHandler for sending span data to telemetry,
/// Please see telemetry documentation for details on how to specify endpoints and
/// set the required telemetry level to activate tracing messages
pub struct TelemetryTraceHandler;
impl TraceHandler for TelemetryTraceHandler {
fn handle_span(&self, span_datum: SpanDatum) {
telemetry!(SUBSTRATE_INFO; "tracing.profiling";
"name" => span_datum.name,
"target" => span_datum.target,
"time" => span_datum.overall_time.as_nanos(),
"id" => span_datum.id.into_u64(),
"parent_id" => span_datum.parent_id.as_ref().map(|i| i.into_u64()),
"values" => span_datum.values
);
}
fn handle_event(&self, event: TraceEvent) {
telemetry!(SUBSTRATE_INFO; "tracing.event";
"name" => event.name,
"target" => event.target,
"parent_id" => event.parent_id.as_ref().map(|i| i.into_u64()),
"values" => event.values
);
}
}
#[cfg(test)]
mod tests {
use super::*;