diff --git a/polkadot/node/core/approval-voting/src/import.rs b/polkadot/node/core/approval-voting/src/import.rs index bbf67fcf18..f1885c52a3 100644 --- a/polkadot/node/core/approval-voting/src/import.rs +++ b/polkadot/node/core/approval-voting/src/import.rs @@ -41,6 +41,7 @@ use polkadot_primitives::v1::{ use polkadot_node_primitives::approval::{ self as approval_types, BlockApprovalMeta, RelayVRFStory, }; +use polkadot_node_jaeger as jaeger; use sc_keystore::LocalKeystore; use sp_consensus_slots::Slot; use kvdb::KeyValueDB; @@ -530,7 +531,7 @@ pub(crate) async fn handle_new_head( ) -> SubsystemResult> { // Update session info based on most recent head. - let mut span = polkadot_node_jaeger::hash_span(&head, "approval-checking-import"); + let mut span = jaeger::Span::new(head, "approval-checking-import"); let header = { let (h_tx, h_rx) = oneshot::channel(); @@ -579,7 +580,7 @@ pub(crate) async fn handle_new_head( .map_err(|e| SubsystemError::with_origin("approval-voting", e)) .await?; - span.add_string_tag("new-blocks", &format!("{}", new_blocks.len())); + span.add_uint_tag("new-blocks", new_blocks.len() as u64); if new_blocks.is_empty() { return Ok(Vec::new()) } diff --git a/polkadot/node/core/approval-voting/src/lib.rs b/polkadot/node/core/approval-voting/src/lib.rs index 3de472fa21..d99a9c10c2 100644 --- a/polkadot/node/core/approval-voting/src/lib.rs +++ b/polkadot/node/core/approval-voting/src/lib.rs @@ -44,7 +44,7 @@ use polkadot_node_primitives::ValidationResult; use polkadot_node_primitives::approval::{ IndirectAssignmentCert, IndirectSignedApprovalVote, ApprovalVote, DelayTranche, }; -use polkadot_node_jaeger::Stage as JaegerStage; +use polkadot_node_jaeger as jaeger; use parity_scale_codec::Encode; use sc_keystore::LocalKeystore; use sp_consensus_slots::Slot; @@ -719,8 +719,8 @@ async fn handle_approved_ancestor( use bitvec::{order::Lsb0, vec::BitVec}; - let mut span = polkadot_node_jaeger::hash_span(&target, "approved-ancestor"); - span.add_stage(JaegerStage::ApprovalChecking); + let mut span = jaeger::Span::new(&target, "approved-ancestor") + .with_stage(jaeger::Stage::ApprovalChecking); let mut all_approved_max = None; @@ -738,8 +738,8 @@ async fn handle_approved_ancestor( if target_number <= lower_bound { return Ok(None) } - span.add_string_tag("target-number", &format!("{}", target_number)); - span.add_string_tag("target-hash", &format!("{}", target)); + span.add_string_fmt_debug_tag("target-number", target_number); + span.add_string_fmt_debug_tag("target-hash", target); // request ancestors up to but not including the lower bound, // as a vote on the lower bound is implied if we cannot find @@ -884,8 +884,8 @@ async fn handle_approved_ancestor( match all_approved_max { Some((ref hash, ref number)) => { - span.add_string_tag("approved-number", &format!("{}", number)); - span.add_string_tag("approved-hash", &format!("{:?}", hash)); + span.add_uint_tag("approved-number", *number as u64); + span.add_string_fmt_debug_tag("approved-hash", hash); } None => { span.add_string_tag("reached-lower-bound", "true"); @@ -1375,15 +1375,13 @@ fn process_wakeup( candidate_hash: CandidateHash, expected_tick: Tick, ) -> SubsystemResult> { - let mut span = polkadot_node_jaeger::descriptor_span( + let _span = jaeger::Span::from_encodable( (relay_block, candidate_hash, expected_tick), "process-approval-wakeup", - ); - - span.add_string_tag("relay-parent", &format!("{:?}", relay_block)); - span.add_string_tag("candidate-hash", &format!("{:?}", candidate_hash)); - span.add_string_tag("tick", &format!("{:?}", expected_tick)); - span.add_stage(JaegerStage::ApprovalChecking); + ) + .with_relay_parent(relay_block) + .with_candidate(candidate_hash) + .with_stage(jaeger::Stage::ApprovalChecking); let block_entry = state.db.load_block_entry(&relay_block)?; let candidate_entry = state.db.load_candidate_entry(&candidate_hash)?; diff --git a/polkadot/node/core/backing/src/lib.rs b/polkadot/node/core/backing/src/lib.rs index 26536876ec..6dd64b56a7 100644 --- a/polkadot/node/core/backing/src/lib.rs +++ b/polkadot/node/core/backing/src/lib.rs @@ -303,7 +303,7 @@ async fn make_pov_available( { let _span = span.as_ref().map(|s| { - s.child_with_candidate("erasure-coding", &candidate_hash) + s.child("erasure-coding").with_candidate(candidate_hash) }); let chunks = erasure_coding::obtain_chunks_v1( @@ -321,7 +321,7 @@ async fn make_pov_available( { let _span = span.as_ref().map(|s| - s.child_with_candidate("store-data", &candidate_hash) + s.child("store-data").with_candidate(candidate_hash) ); store_available_data( @@ -416,10 +416,9 @@ async fn validate_and_make_available( let v = { let _span = span.as_ref().map(|s| { - s.child_builder("request-validation") + s.child("request-validation") .with_pov(&pov) .with_para_id(candidate.descriptor().para_id) - .build() }); request_candidate_validation(&mut tx_from, candidate.descriptor.clone(), pov.clone()).await? }; @@ -631,7 +630,7 @@ impl CandidateBackingJob { candidate.descriptor().para_id, ); - span.as_mut().map(|s| s.add_follows_from(parent_span)); + span.as_mut().map(|span| span.add_follows_from(parent_span)); tracing::debug!( target: LOG_TARGET, @@ -761,12 +760,11 @@ impl CandidateBackingJob { CandidateBackingMessage::Second(relay_parent, candidate, pov) => { let _timer = self.metrics.time_process_second(); - let span = root_span.child_builder("second") + let span = root_span.child("second") .with_stage(jaeger::Stage::CandidateBacking) .with_pov(&pov) - .with_candidate(&candidate.hash()) - .with_relay_parent(&relay_parent) - .build(); + .with_candidate(candidate.hash()) + .with_relay_parent(relay_parent); // Sanity check that candidate is from our assignment. if Some(candidate.descriptor().para_id) != self.assignment { @@ -788,11 +786,10 @@ impl CandidateBackingJob { } CandidateBackingMessage::Statement(_relay_parent, statement) => { let _timer = self.metrics.time_process_statement(); - let span = root_span.child_builder("statement") + let span = root_span.child("statement") .with_stage(jaeger::Stage::CandidateBacking) - .with_candidate(&statement.payload().candidate_hash()) - .with_relay_parent(&_relay_parent) - .build(); + .with_candidate(statement.payload().candidate_hash()) + .with_relay_parent(_relay_parent); self.check_statement_signature(&statement)?; match self.maybe_validate_and_import(&span, &root_span, statement).await { @@ -934,14 +931,12 @@ impl CandidateBackingJob { if !self.backed.contains(&hash) { // only add if we don't consider this backed. let span = self.unbacked_candidates.entry(hash).or_insert_with(|| { - let s = parent_span.child_builder("unbacked-candidate").with_candidate(&hash); - let s = if let Some(para_id) = para_id { + let s = parent_span.child("unbacked-candidate").with_candidate(hash); + if let Some(para_id) = para_id { s.with_para_id(para_id) } else { s - }; - - s.build() + } }); Some(span) } else { @@ -957,10 +952,9 @@ impl CandidateBackingJob { ) -> Option { self.insert_or_get_unbacked_span(parent_span, hash, Some(para_id)) .map(|span| { - span.child_builder("validation") - .with_candidate(&hash) + span.child("validation") + .with_candidate(hash) .with_stage(Stage::CandidateBacking) - .build() }) } @@ -971,10 +965,9 @@ impl CandidateBackingJob { validator: ValidatorIndex, ) -> Option { self.insert_or_get_unbacked_span(parent_span, hash, None).map(|span| { - span.child_builder("import-statement") - .with_candidate(&hash) + span.child("import-statement") + .with_candidate(hash) .with_validator_index(validator) - .build() }) } diff --git a/polkadot/node/core/candidate-selection/src/lib.rs b/polkadot/node/core/candidate-selection/src/lib.rs index a12e25b234..5b9e3a57c4 100644 --- a/polkadot/node/core/candidate-selection/src/lib.rs +++ b/polkadot/node/core/candidate-selection/src/lib.rs @@ -104,10 +104,9 @@ impl JobTrait for CandidateSelectionJob { ) -> Pin> + Send>> { let span = PerLeafSpan::new(span, "candidate-selection"); async move { - let _span = span.child_builder("query-runtime") - .with_relay_parent(&relay_parent) - .with_stage(jaeger::Stage::CandidateSelection) - .build(); + let _span = span.child("query-runtime") + .with_relay_parent(relay_parent) + .with_stage(jaeger::Stage::CandidateSelection); let (groups, cores) = futures::try_join!( try_runtime_api!(request_validator_groups(relay_parent, &mut sender).await), try_runtime_api!(request_from_runtime( @@ -121,10 +120,9 @@ impl JobTrait for CandidateSelectionJob { let cores = try_runtime_api!(cores); drop(_span); - let _span = span.child_builder("validator-construction") - .with_relay_parent(&relay_parent) - .with_stage(jaeger::Stage::CandidateSelection) - .build(); + let _span = span.child("validator-construction") + .with_relay_parent(relay_parent) + .with_stage(jaeger::Stage::CandidateSelection); let n_cores = cores.len(); @@ -134,10 +132,9 @@ impl JobTrait for CandidateSelectionJob { Err(err) => return Err(Error::Util(err)), }; - let mut assignment_span = span.child_builder("find-assignment") - .with_relay_parent(&relay_parent) - .with_stage(jaeger::Stage::CandidateSelection) - .build(); + let assignment_span = span.child("find-assignment") + .with_relay_parent(relay_parent) + .with_stage(jaeger::Stage::CandidateSelection); #[derive(Debug)] enum AssignmentState { @@ -172,15 +169,16 @@ impl JobTrait for CandidateSelectionJob { } } - let assignment = match assignment { + let (assignment, assignment_span) = match assignment { AssignmentState::Scheduled(assignment) => { - assignment_span.add_string_tag("assigned", "true"); - assignment_span.add_para_id(assignment); + let assignment_span = assignment_span + .with_string_tag("assigned", "true") + .with_para_id(assignment); - assignment + (assignment, assignment_span) } assignment => { - assignment_span.add_string_tag("assigned", "false"); + let _assignment_span = assignment_span.with_string_tag("assigned", "false"); let validator_index = validator.index(); let validator_id = validator.id(); @@ -222,9 +220,8 @@ impl CandidateSelectionJob { } async fn run_loop(&mut self, span: &jaeger::Span) -> Result<(), Error> { - let span = span.child_builder("run-loop") - .with_stage(jaeger::Stage::CandidateSelection) - .build(); + let span = span.child("run-loop") + .with_stage(jaeger::Stage::CandidateSelection); loop { match self.receiver.next().await { @@ -240,19 +237,17 @@ impl CandidateSelectionJob { _relay_parent, candidate_receipt, )) => { - let _span = span.child_builder("handle-invalid") + let _span = span.child("handle-invalid") .with_stage(jaeger::Stage::CandidateSelection) - .with_candidate(&candidate_receipt.hash()) - .with_relay_parent(&_relay_parent) - .build(); + .with_candidate(candidate_receipt.hash()) + .with_relay_parent(_relay_parent); self.handle_invalid(candidate_receipt).await; } Some(CandidateSelectionMessage::Seconded(_relay_parent, statement)) => { - let _span = span.child_builder("handle-seconded") + let _span = span.child("handle-seconded") .with_stage(jaeger::Stage::CandidateSelection) - .with_candidate(&statement.payload().candidate_hash()) - .with_relay_parent(&_relay_parent) - .build(); + .with_candidate(statement.payload().candidate_hash()) + .with_relay_parent(_relay_parent); self.handle_seconded(statement).await; } None => break, diff --git a/polkadot/node/core/proposer/src/lib.rs b/polkadot/node/core/proposer/src/lib.rs index 241665b57d..822f38f8a8 100644 --- a/polkadot/node/core/proposer/src/lib.rs +++ b/polkadot/node/core/proposer/src/lib.rs @@ -203,7 +203,7 @@ where max_duration: time::Duration, ) -> Self::Proposal { async move { - let span = jaeger::hash_span(&self.parent_header_hash, "propose"); + let span = jaeger::Span::new(self.parent_header_hash, "propose"); let _span = span.child("get-provisioner"); let provisioner_data = match self.get_provisioner_data().await { diff --git a/polkadot/node/core/provisioner/src/lib.rs b/polkadot/node/core/provisioner/src/lib.rs index 64486bbf27..de5f3eb036 100644 --- a/polkadot/node/core/provisioner/src/lib.rs +++ b/polkadot/node/core/provisioner/src/lib.rs @@ -245,8 +245,8 @@ impl ProvisioningJob { self.signed_bitfields.push(signed_bitfield) } ProvisionableData::BackedCandidate(backed_candidate) => { - let mut span = span.child("provisionable-backed"); - span.add_para_id(backed_candidate.descriptor().para_id); + let _span = span.child("provisionable-backed") + .with_para_id(backed_candidate.descriptor().para_id); self.backed_candidates.push(backed_candidate) } _ => {} diff --git a/polkadot/node/jaeger/src/config.rs b/polkadot/node/jaeger/src/config.rs new file mode 100644 index 0000000000..777d7705f5 --- /dev/null +++ b/polkadot/node/jaeger/src/config.rs @@ -0,0 +1,73 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Polkadot Jaeger configuration. + +/// Configuration for the jaeger tracing. +#[derive(Clone)] +pub struct JaegerConfig { + pub(crate) node_name: String, + pub(crate) agent_addr: std::net::SocketAddr, +} + +impl std::default::Default for JaegerConfig { + fn default() -> Self { + Self { + node_name: "unknown_".to_owned(), + agent_addr: "127.0.0.1:6831" + .parse() + .expect(r#"Static "127.0.0.1:6831" is a valid socket address string. qed"#), + } + } +} + +impl JaegerConfig { + /// Use the builder pattern to construct a configuration. + pub fn builder() -> JaegerConfigBuilder { + JaegerConfigBuilder::default() + } +} + +/// Jaeger configuration builder. +#[derive(Default)] +pub struct JaegerConfigBuilder { + inner: JaegerConfig, +} + +impl JaegerConfigBuilder { + /// Set the name for this node. + pub fn named(mut self, name: S) -> Self + where + S: AsRef, + { + self.inner.node_name = name.as_ref().to_owned(); + self + } + + /// Set the agent address to send the collected spans to. + pub fn agent(mut self, addr: U) -> Self + where + U: Into, + { + self.inner.agent_addr = addr.into(); + self + } + + /// Construct the configuration. + pub fn build(self) -> JaegerConfig { + self.inner + } +} diff --git a/polkadot/node/jaeger/src/errors.rs b/polkadot/node/jaeger/src/errors.rs new file mode 100644 index 0000000000..cf5cdc1e86 --- /dev/null +++ b/polkadot/node/jaeger/src/errors.rs @@ -0,0 +1,28 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Polkadot Jaeger error definitions. + +/// A description of an error during jaeger initialization. +#[derive(Debug, thiserror::Error)] +#[allow(missing_docs)] +pub enum JaegerError { + #[error("Already launched the collector thread")] + AlreadyLaunched, + + #[error("Missing jaeger configuration")] + MissingConfiguration, +} diff --git a/polkadot/node/jaeger/src/lib.rs b/polkadot/node/jaeger/src/lib.rs index d376c4a756..4b88966f3f 100644 --- a/polkadot/node/jaeger/src/lib.rs +++ b/polkadot/node/jaeger/src/lib.rs @@ -25,7 +25,7 @@ //! The easiest way to try Jaeger is: //! //! - Start a docker container with the all-in-one docker image (see below). -//! - Open your browser and navigate to to acces the UI. +//! - Open your browser and navigate to to access the UI. //! //! The all-in-one image can be started with: //! @@ -44,375 +44,27 @@ //! docker.io/jaegertracing/all-in-one:1.21 //! ``` +#![forbid(unused_imports)] + +mod config; +mod errors; +mod spans; + +pub use self::config::{JaegerConfig, JaegerConfigBuilder}; +pub use self::errors::JaegerError; +pub use self::spans::{PerLeafSpan, Span, Stage}; + +use self::spans::TraceIdentifier; + use sp_core::traits::SpawnNamed; -use polkadot_primitives::v1::{CandidateHash, Hash, PoV, ValidatorIndex, BlakeTwo256, HashT, Id as ParaId}; -use parity_scale_codec::Encode; -use sc_network::PeerId; use parking_lot::RwLock; -use std::{sync::Arc, result}; - -/// A description of an error causing the chain API request to be unservable. -#[derive(Debug, thiserror::Error)] -#[allow(missing_docs)] -pub enum JaegerError { - #[error("Already launched the collector thread")] - AlreadyLaunched, - - #[error("Missing jaeger configuration")] - MissingConfiguration, -} +use std::{result, sync::Arc}; lazy_static::lazy_static! { static ref INSTANCE: RwLock = RwLock::new(Jaeger::None); } -/// Configuration for the jaeger tracing. -#[derive(Clone)] -pub struct JaegerConfig { - node_name: String, - agent_addr: std::net::SocketAddr, -} - -impl std::default::Default for JaegerConfig { - fn default() -> Self { - Self { - node_name: "unknown_".to_owned(), - agent_addr: "127.0.0.1:6831".parse().expect(r#"Static "127.0.0.1:6831" is a valid socket address string. qed"#), - } - } -} - -impl JaegerConfig { - /// Use the builder pattern to construct a configuration. - pub fn builder() -> JaegerConfigBuilder { - JaegerConfigBuilder::default() - } -} - - -/// Jaeger configuration builder. -#[derive(Default)] -pub struct JaegerConfigBuilder { - inner: JaegerConfig -} - -impl JaegerConfigBuilder { - /// Set the name for this node. - pub fn named(mut self, name: S) -> Self where S: AsRef { - self.inner.node_name = name.as_ref().to_owned(); - self - } - - /// Set the agent address to send the collected spans to. - pub fn agent(mut self, addr: U) -> Self where U: Into { - self.inner.agent_addr = addr.into(); - self - } - - /// Construct the configuration. - pub fn build(self) -> JaegerConfig { - self.inner - } -} - -/// A special "per leaf span". -/// -/// Essentially this span wraps two spans: -/// -/// 1. The span that is created per leaf in the overseer. -/// 2. Some child span of the per-leaf span. -/// -/// This just works as auxiliary structure to easily store both. -#[derive(Debug)] -pub struct PerLeafSpan { - leaf_span: Arc, - span: Span, -} - -impl PerLeafSpan { - /// Creates a new instance. - /// - /// Takes the `leaf_span` that is created by the overseer per leaf and a name for a child span. - /// Both will be stored in this object, while the child span is implicitly accessible by using the - /// [`Deref`](std::ops::Deref) implementation. - pub fn new(leaf_span: Arc, name: &'static str) -> Self { - let span = leaf_span.child(name); - - Self { - span, - leaf_span, - } - } - - /// Returns the leaf span. - pub fn leaf_span(&self) -> &Arc { - &self.leaf_span - } -} - -/// Returns a reference to the child span. -impl std::ops::Deref for PerLeafSpan { - type Target = Span; - - fn deref(&self) -> &Span { - &self.span - } -} - - -/// A helper to annotate the stage with a numerical value -/// to ease the life of the tooling team creating viable -/// statistical metrics for which stage of the inclusion -/// pipeline drops a significant amount of candidates, -/// statistically speaking. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(u8)] -#[non_exhaustive] -pub enum Stage { - CandidateSelection = 1, - CandidateBacking = 2, - StatementDistribution = 3, - PoVDistribution = 4, - AvailabilityDistribution = 5, - AvailabilityRecovery = 6, - BitfieldDistribution = 7, - ApprovalChecking = 8, - // Expand as needed, numbers should be ascending according to the stage - // through the inclusion pipeline, or according to the descriptions - // in [the path of a para chain block] - // (https://polkadot.network/the-path-of-a-parachain-block/) - // see [issue](https://github.com/paritytech/polkadot/issues/2389) -} - -/// Builder pattern for children and root spans to unify -/// information annotations. -pub struct SpanBuilder { - span: Span, -} - -impl SpanBuilder { - /// Attach a peer id to the span. - #[inline(always)] - pub fn with_peer_id(mut self, peer: &PeerId) -> Self { - self.span.add_string_tag("peer-id", &peer.to_base58()); - self - } - /// Attach a candidate hash to the span. - #[inline(always)] - pub fn with_candidate(mut self, candidate_hash: &CandidateHash) -> Self { - self.span.add_string_tag("candidate-hash", &format!("{:?}", candidate_hash.0)); - self - } - - /// Attach a para-id to the span. - #[inline(always)] - pub fn with_para_id(mut self, para_id: ParaId) -> Self { - self.span.add_para_id(para_id); - self - } - - /// Attach a candidate stage. - /// Should always come with a `CandidateHash`. - #[inline(always)] - pub fn with_stage(mut self, stage: Stage) -> Self { - self.span.add_stage(stage); - self - } - - #[inline(always)] - pub fn with_validator_index(mut self, validator: ValidatorIndex) -> Self { - self.span.add_string_tag("validator-index", &validator.0.to_string()); - self - } - - #[inline(always)] - pub fn with_chunk_index(mut self, chunk_index: u32) -> Self { - self.span.add_string_tag("chunk-index", &format!("{}", chunk_index)); - self - } - - #[inline(always)] - pub fn with_relay_parent(mut self, relay_parent: &Hash) -> Self { - self.span.add_string_tag("relay-parent", &format!("{:?}", relay_parent)); - self - } - - #[inline(always)] - pub fn with_claimed_validator_index(mut self, claimed_validator_index: ValidatorIndex) -> Self { - self.span.add_string_tag( - "claimed-validator", - &claimed_validator_index.0.to_string(), - ); - self - } - - #[inline(always)] - pub fn with_pov(mut self, pov: &PoV) -> Self { - self.span.add_pov(pov); - self - } - - /// Complete construction. - #[inline(always)] - pub fn build(self) -> Span { - self.span - } -} - - -/// A wrapper type for a span. -/// -/// Handles running with and without jaeger. -pub enum Span { - /// Running with jaeger being enabled. - Enabled(mick_jaeger::Span), - /// Running with jaeger disabled. - Disabled, -} - -impl Span { - /// Derive a child span from `self`. - pub fn child(&self, name: &'static str) -> Self { - match self { - Self::Enabled(inner) => Self::Enabled(inner.child(name)), - Self::Disabled => Self::Disabled, - } - } - - pub fn child_builder(&self, name: &'static str) -> SpanBuilder { - SpanBuilder { - span: self.child(name), - } - } - - /// Derive a child span from `self` but add a candidate annotation. - /// A shortcut for - /// - /// ```rust,no_run - /// # use polkadot_primitives::v1::CandidateHash; - /// # use polkadot_node_jaeger::candidate_hash_span; - /// # let hash = CandidateHash::default(); - /// # let span = candidate_hash_span(&hash, "foo"); - /// let _span = span.child_builder("name").with_candidate(&hash).build(); - /// ``` - #[inline(always)] - pub fn child_with_candidate(&self, name: &'static str, candidate_hash: &CandidateHash) -> Self { - self.child_builder(name).with_candidate(candidate_hash).build() - } - - /// Add candidate stage annotation. - pub fn add_stage(&mut self, stage: Stage) { - self.add_string_tag("candidate-stage", &format!("{}", stage as u8)); - } - - pub fn add_pov(&mut self, pov: &PoV) { - if self.is_enabled() { - // avoid computing the pov hash if jaeger is not enabled - self.add_string_tag("pov", &format!("{:?}", pov.hash())); - } - } - - /// Add the para-id to the span. - pub fn add_para_id(&mut self, para_id: ParaId) { - self.add_int_tag("para-id", u32::from(para_id) as i64); - } - - /// Add an additional tag to the span. - pub fn add_string_tag(&mut self, tag: &str, value: &str) { - match self { - Self::Enabled(ref mut inner) => inner.add_string_tag(tag, value), - Self::Disabled => {}, - } - } - - /// Add an additional int tag to the span. - pub fn add_int_tag(&mut self, tag: &str, value: i64) { - match self { - Self::Enabled(ref mut inner) => inner.add_int_tag(tag, value), - Self::Disabled => {}, - } - } - - /// Adds the `FollowsFrom` relationship to this span with respect to the given one. - pub fn add_follows_from(&mut self, other: &Self) { - match (self, other) { - (Self::Enabled(ref mut inner), Self::Enabled(ref other_inner)) => inner.add_follows_from(&other_inner), - _ => {}, - } - } - - /// Helper to check whether jaeger is enabled - /// in order to avoid computational overhead. - pub const fn is_enabled(&self) -> bool { - match self { - Span::Enabled(_) => true, - _ => false, - } - } -} - -impl std::fmt::Debug for Span { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "") - } -} - -impl From> for Span { - fn from(src: Option) -> Self { - if let Some(span) = src { - Self::Enabled(span) - } else { - Self::Disabled - } - } -} - -impl From for Span { - fn from(src: mick_jaeger::Span) -> Self { - Self::Enabled(src) - } -} - -/// Shortcut for [`hash_span`] with the hash of the `Candidate` block. -pub fn candidate_hash_span(candidate_hash: &CandidateHash, span_name: &'static str) -> Span { - let mut span: Span = INSTANCE.read_recursive() - .span(|| { candidate_hash.0 }, span_name).into(); - - span.add_string_tag("candidate-hash", &format!("{:?}", candidate_hash.0)); - span -} - -/// Shortcut for [`hash_span`] with the hash of the `PoV`. -#[inline(always)] -pub fn pov_span(pov: &PoV, span_name: &'static str) -> Span { - let mut span: Span = INSTANCE.read_recursive() - .span(|| { pov.hash() }, span_name).into(); - - span.add_pov(pov); - span -} - -/// Creates a `Span` referring to the given hash. All spans created with [`hash_span`] with the -/// same hash (even from multiple different nodes) will be visible in the same view on Jaeger. -/// -/// This span automatically has the `relay-parent` tag set. -#[inline(always)] -pub fn hash_span(hash: &Hash, span_name: &'static str) -> Span { - let mut span: Span = INSTANCE.read_recursive().span(|| { *hash }, span_name).into(); - span.add_string_tag("relay-parent", &format!("{:?}", hash)); - span -} - -/// Creates a `Span` referring to the given descriptor, which should be unique. -#[inline(always)] -pub fn descriptor_span(descriptor: impl Encode, span_name: &'static str) -> Span { - INSTANCE.read_recursive().span( - || { BlakeTwo256::hash_of(&descriptor) }, - span_name, - ).into() -} - /// Stateful convenience wrapper around [`mick_jaeger`]. pub enum Jaeger { /// Launched and operational state. @@ -443,9 +95,7 @@ impl Jaeger { pub fn launch(self, spawner: S) -> result::Result<(), JaegerError> { let cfg = match self { Self::Prep(cfg) => Ok(cfg), - Self::Launched{ .. } => { - return Err(JaegerError::AlreadyLaunched) - } + Self::Launched { .. } => return Err(JaegerError::AlreadyLaunched), Self::None => Err(JaegerError::MissingConfiguration), }?; @@ -453,41 +103,39 @@ impl Jaeger { log::info!("🐹 Collecting jaeger spans for {:?}", &jaeger_agent); - let (traces_in, mut traces_out) = mick_jaeger::init(mick_jaeger::Config { - service_name: format!("polkadot-{}", cfg.node_name), - }); + let (traces_in, mut traces_out) = + mick_jaeger::init(mick_jaeger::Config { service_name: format!("polkadot-{}", cfg.node_name) }); // Spawn a background task that pulls span information and sends them on the network. - spawner.spawn("jaeger-collector", Box::pin(async move { - match async_std::net::UdpSocket::bind("0.0.0.0:0").await { - Ok(udp_socket) => loop { - let buf = traces_out.next().await; - // UDP sending errors happen only either if the API is misused or in case of missing privilege. - if let Err(e) = udp_socket.send_to(&buf, jaeger_agent).await { - log::debug!(target: "jaeger", "UDP send error: {}", e); + spawner.spawn( + "jaeger-collector", + Box::pin(async move { + match async_std::net::UdpSocket::bind("0.0.0.0:0").await { + Ok(udp_socket) => loop { + let buf = traces_out.next().await; + // UDP sending errors happen only either if the API is misused or in case of missing privilege. + if let Err(e) = udp_socket.send_to(&buf, jaeger_agent).await { + log::debug!(target: "jaeger", "UDP send error: {}", e); + } + }, + Err(e) => { + log::warn!(target: "jaeger", "UDP socket open error: {}", e); } } - Err(e) => { - log::warn!(target: "jaeger", "UDP socket open error: {}", e); - } - } - })); + }), + ); - *INSTANCE.write() = Self::Launched { - traces_in, - }; + *INSTANCE.write() = Self::Launched { traces_in }; Ok(()) } - fn span(&self, lazy_hash: F, span_name: &'static str) -> Option + pub(crate) fn span(&self, lazy_hash: F, span_name: &'static str) -> Option where - F: Fn() -> Hash, + F: Fn() -> TraceIdentifier, { - if let Self::Launched { traces_in , .. } = self { - let hash = lazy_hash(); - let mut buf = [0u8; 16]; - buf.copy_from_slice(&hash.as_ref()[0..16]); - let trace_id = std::num::NonZeroU128::new(u128::from_be_bytes(buf))?; + if let Self::Launched { traces_in, .. } = self { + let ident = lazy_hash(); + let trace_id = std::num::NonZeroU128::new(ident)?; Some(traces_in.span(trace_id, span_name)) } else { None diff --git a/polkadot/node/jaeger/src/spans.rs b/polkadot/node/jaeger/src/spans.rs new file mode 100644 index 0000000000..952133f5c6 --- /dev/null +++ b/polkadot/node/jaeger/src/spans.rs @@ -0,0 +1,431 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Polkadot Jaeger span definitions. +//! +//! ```rust +//! # use polkadot_primitives::v1::{CandidateHash, Hash}; +//! # fn main() { +//! use polkadot_node_jaeger as jaeger; +//! +//! let relay_parent = Hash::default(); +//! let candidate = CandidateHash::default(); +//! +//! #[derive(Debug, Default)] +//! struct Foo { +//! a: u8, +//! b: u16, +//! c: u32, +//! }; +//! +//! let foo = Foo::default(); +//! +//! let span = +//! jaeger::Span::new(relay_parent, "root_of_aaall_spans") +//! // explicit well defined items +//! .with_candidate(candidate) +//! // anything that implements `trait std::fmt::Debug` +//! .with_string_fmt_debug_tag("foo", foo) +//! // anything that implements `trait std::str::ToString` +//! .with_string_tag("again", 1337_u32) +//! // add a `Stage` for [`dot-jaeger`](https://github.com/paritytech/dot-jaeger) +//! .with_stage(jaeger::Stage::CandidateBacking); +//! // complete by design, no completion required +//! # } +//! ``` +//! +//! In a few cases additional annotations might want to be added +//! over the course of a function, for this purpose use the non-consuming +//! `fn` variants, i.e. +//! ```rust +//! # use polkadot_primitives::v1::{CandidateHash, Hash}; +//! # fn main() { +//! # use polkadot_node_jaeger as jaeger; +//! +//! # let relay_parent = Hash::default(); +//! # let candidate = CandidateHash::default(); +//! +//! # #[derive(Debug, Default)] +//! # struct Foo { +//! # a: u8, +//! # b: u16, +//! # c: u32, +//! # }; +//! # +//! # let foo = Foo::default(); +//! +//! let root_span = +//! jaeger::Span::new(relay_parent, "root_of_aaall_spans"); +//! +//! // the prefered way of adding additional delayed information: +//! let span = root_span.child("inner"); +//! +//! // ... more operations ... +//! +//! // but this is also possible: +//! +//! let mut root_span = root_span; +//! root_span.add_string_fmt_debug_tag("foo_constructed", &foo); +//! root_span.add_string_tag("bar", true); +//! # } +//! ``` + +use parity_scale_codec::Encode; +use polkadot_primitives::v1::{BlakeTwo256, CandidateHash, Hash, HashT, Id as ParaId, PoV, ValidatorIndex}; +use sc_network::PeerId; + +use std::fmt; +use std::sync::Arc; + +use super::INSTANCE; + +/// A special "per leaf span". +/// +/// Essentially this span wraps two spans: +/// +/// 1. The span that is created per leaf in the overseer. +/// 2. Some child span of the per-leaf span. +/// +/// This just works as auxiliary structure to easily store both. +#[derive(Debug)] +pub struct PerLeafSpan { + leaf_span: Arc, + span: Span, +} + +impl PerLeafSpan { + /// Creates a new instance. + /// + /// Takes the `leaf_span` that is created by the overseer per leaf and a name for a child span. + /// Both will be stored in this object, while the child span is implicitly accessible by using the + /// [`Deref`](std::ops::Deref) implementation. + pub fn new(leaf_span: Arc, name: &'static str) -> Self { + let span = leaf_span.child(name); + + Self { span, leaf_span } + } + + /// Returns the leaf span. + pub fn leaf_span(&self) -> &Arc { + &self.leaf_span + } +} + +/// Returns a reference to the child span. +impl std::ops::Deref for PerLeafSpan { + type Target = Span; + + fn deref(&self) -> &Span { + &self.span + } +} + +/// A helper to annotate the stage with a numerical value +/// to ease the life of the tooling team creating viable +/// statistical metrics for which stage of the inclusion +/// pipeline drops a significant amount of candidates, +/// statistically speaking. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u8)] +#[non_exhaustive] +pub enum Stage { + CandidateSelection = 1, + CandidateBacking = 2, + StatementDistribution = 3, + PoVDistribution = 4, + AvailabilityDistribution = 5, + AvailabilityRecovery = 6, + BitfieldDistribution = 7, + ApprovalChecking = 8, + // Expand as needed, numbers should be ascending according to the stage + // through the inclusion pipeline, or according to the descriptions + // in [the path of a para chain block] + // (https://polkadot.network/the-path-of-a-parachain-block/) + // see [issue](https://github.com/paritytech/polkadot/issues/2389) +} + +/// A wrapper type for a span. +/// +/// Handles running with and without jaeger. +pub enum Span { + /// Running with jaeger being enabled. + Enabled(mick_jaeger::Span), + /// Running with jaeger disabled. + Disabled, +} + +/// Alias for the 16 byte unique identifier used with jaeger. +pub(crate) type TraceIdentifier = u128; + +/// A helper to convert the hash to the fixed size representation +/// needed for jaeger. +#[inline] +fn hash_to_identifier(hash: Hash) -> TraceIdentifier { + let mut buf = [0u8; 16]; + buf.copy_from_slice(&hash.as_ref()[0..16]); + u128::from_be_bytes(buf) as TraceIdentifier +} + +/// Helper to unify lazy proxy evaluation. +pub trait LazyIdent { + /// Evaluate the type to a unique trace identifier. + /// Called lazily on demand. + fn eval(&self) -> TraceIdentifier; + + /// Annotate a new root item with these additional spans + /// at construction. + fn extra_tags(&self, _span: &mut Span) {} +} + +impl<'a> LazyIdent for &'a [u8] { + fn eval(&self) -> TraceIdentifier { + hash_to_identifier(BlakeTwo256::hash_of(self)) + } +} + +impl LazyIdent for &PoV { + fn eval(&self) -> TraceIdentifier { + hash_to_identifier(self.hash()) + } + + fn extra_tags(&self, span: &mut Span) { + span.add_pov(self) + } +} + +impl LazyIdent for Hash { + fn eval(&self) -> TraceIdentifier { + hash_to_identifier(*self) + } + + fn extra_tags(&self, span: &mut Span) { + span.add_string_fmt_debug_tag("relay-parent", self.0); + } +} + +impl LazyIdent for &Hash { + fn eval(&self) -> TraceIdentifier { + hash_to_identifier(**self) + } + + fn extra_tags(&self, span: &mut Span) { + span.add_string_fmt_debug_tag("relay-parent", self.0); + } +} + +impl LazyIdent for CandidateHash { + fn eval(&self) -> TraceIdentifier { + hash_to_identifier(self.0) + } + + fn extra_tags(&self, span: &mut Span) { + span.add_string_fmt_debug_tag("candidate-hash", &self.0); + } +} + +impl Span { + /// Creates a new span builder based on anything that can be lazily evaluated + /// to and identifier. + pub fn new(identifier: I, span_name: &'static str) -> Span { + let mut span = INSTANCE.read_recursive().span(|| ::eval(&identifier), span_name).into(); + ::extra_tags(&identifier, &mut span); + span + } + + /// Creates a new span builder based on an encodable type. + /// The encoded bytes are then used to derive the true trace identifier. + pub fn from_encodable(identifier: I, span_name: &'static str) -> Span { + INSTANCE + .read_recursive() + .span( + move || { + let bytes = identifier.encode(); + LazyIdent::eval(&bytes.as_slice()) + }, + span_name, + ) + .into() + } + + /// Derive a child span from `self`. + pub fn child(&self, name: &'static str) -> Self { + match self { + Self::Enabled(inner) => Self::Enabled(inner.child(name)), + Self::Disabled => Self::Disabled, + } + } + + #[inline(always)] + pub fn with_string_tag(mut self, tag: &'static str, val: V) -> Self { + self.add_string_tag::(tag, val); + self + } + + #[inline(always)] + pub fn with_peer_id(self, peer: &PeerId) -> Self { + self.with_string_tag("peer-id", &peer.to_base58()) + } + + /// Attach a candidate hash to the span. + #[inline(always)] + pub fn with_candidate(self, candidate_hash: CandidateHash) -> Self { + self.with_string_fmt_debug_tag("candidate-hash", &candidate_hash.0) + } + + /// Attach a para-id to the span. + #[inline(always)] + pub fn with_para_id(self, para_id: ParaId) -> Self { + self.with_int_tag("para-id", u32::from(para_id) as i64) + } + + /// Attach a candidate stage. + /// Should always come with a `CandidateHash`. + #[inline(always)] + pub fn with_stage(self, stage: Stage) -> Self { + self.with_string_tag("candidate-stage", stage as u8) + } + + #[inline(always)] + pub fn with_validator_index(self, validator: ValidatorIndex) -> Self { + self.with_string_tag("validator-index", &validator.0) + } + + #[inline(always)] + pub fn with_chunk_index(self, chunk_index: u32) -> Self { + self.with_string_tag("chunk-index", chunk_index) + } + + #[inline(always)] + pub fn with_relay_parent(self, relay_parent: Hash) -> Self { + self.with_string_fmt_debug_tag("relay-parent", relay_parent) + } + + #[inline(always)] + pub fn with_claimed_validator_index(self, claimed_validator_index: ValidatorIndex) -> Self { + self.with_string_tag("claimed-validator", &claimed_validator_index.0) + } + + #[inline(always)] + pub fn with_pov(mut self, pov: &PoV) -> Self { + self.add_pov(pov); + self + } + + /// Add an additional int tag to the span without consuming. + /// + /// Should be used sparingly, introduction of new types is prefered. + #[inline(always)] + pub fn with_int_tag(mut self, tag: &'static str, i: i64) -> Self { + self.add_int_tag(tag, i); + self + } + + #[inline(always)] + pub fn with_uint_tag(mut self, tag: &'static str, u: u64) -> Self { + self.add_uint_tag(tag, u); + self + } + + #[inline(always)] + pub fn with_string_fmt_debug_tag(mut self, tag: &'static str, val: V) -> Self { + self.add_string_tag(tag, format!("{:?}", val)); + self + } + + /// Adds the `FollowsFrom` relationship to this span with respect to the given one. + #[inline(always)] + pub fn add_follows_from(&mut self, other: &Self) { + match (self, other) { + (Self::Enabled(ref mut inner), Self::Enabled(ref other_inner)) => inner.add_follows_from(&other_inner), + _ => {} + } + } + + /// Add a pov hash meta tag with lazy hash eval, without consuming the span. + #[inline(always)] + pub fn add_pov(&mut self, pov: &PoV) { + if self.is_enabled() { + // avoid computing the pov hash if jaeger is not enabled + self.add_string_fmt_debug_tag("pov", pov.hash()); + } + } + + #[inline(always)] + pub fn add_para_id(&mut self, para_id: ParaId) { + self.add_int_tag("para-id", u32::from(para_id) as i64); + } + + /// Add a string tag, without consuming the span. + pub fn add_string_tag(&mut self, tag: &'static str, val: V) { + match self { + Self::Enabled(ref mut inner) => inner.add_string_tag(tag, val.to_string().as_str()), + Self::Disabled => {} + } + } + + /// Add a string tag, without consuming the span. + pub fn add_string_fmt_debug_tag(&mut self, tag: &'static str, val: V) { + match self { + Self::Enabled(ref mut inner) => inner.add_string_tag(tag, format!("{:?}", val).as_str()), + Self::Disabled => {} + } + } + + pub fn add_int_tag(&mut self, tag: &'static str, value: i64) { + match self { + Self::Enabled(ref mut inner) => inner.add_int_tag(tag, value), + Self::Disabled => {} + } + } + + pub fn add_uint_tag(&mut self, tag: &'static str, value: u64) { + match self { + Self::Enabled(ref mut inner) => inner.add_int_tag(tag, value as i64), + Self::Disabled => {} + } + } + + /// Check whether jaeger is enabled + /// in order to avoid computational overhead. + pub const fn is_enabled(&self) -> bool { + match self { + Span::Enabled(_) => true, + _ => false, + } + } +} + +impl std::fmt::Debug for Span { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "") + } +} + +impl From> for Span { + fn from(src: Option) -> Self { + if let Some(span) = src { + Self::Enabled(span) + } else { + Self::Disabled + } + } +} + +impl From for Span { + fn from(src: mick_jaeger::Span) -> Self { + Self::Enabled(src) + } +} diff --git a/polkadot/node/network/availability-distribution/src/requester/fetch_task/mod.rs b/polkadot/node/network/availability-distribution/src/requester/fetch_task/mod.rs index 17a2769b2a..6096081ed2 100644 --- a/polkadot/node/network/availability-distribution/src/requester/fetch_task/mod.rs +++ b/polkadot/node/network/availability-distribution/src/requester/fetch_task/mod.rs @@ -116,7 +116,7 @@ struct RunningTask { /// Sender for communicating with other subsystems and reporting results. sender: mpsc::Sender, - + /// Prometheues metrics for reporting results. metrics: Metrics, @@ -145,8 +145,8 @@ impl FetchTaskConfig { }; } - let mut span = jaeger::candidate_hash_span(&core.candidate_hash, "availability-distribution"); - span.add_stage(jaeger::Stage::AvailabilityDistribution); + let span = jaeger::Span::new(core.candidate_hash, "availability-distribution") + .with_stage(jaeger::Stage::AvailabilityDistribution); let prepared_running = RunningTask { session_index: session_info.session_index, @@ -263,10 +263,9 @@ impl RunningTask { let mut bad_validators = Vec::new(); let mut label = FAILED; let mut count: u32 = 0; - let mut _span = self.span.child_builder("fetch-task") + let mut _span = self.span.child("fetch-task") .with_chunk_index(self.request.index.0) - .with_relay_parent(&self.relay_parent) - .build(); + .with_relay_parent(self.relay_parent); // Try validators in reverse order: while let Some(validator) = self.group.pop() { let _try_span = _span.child("try"); diff --git a/polkadot/node/network/availability-distribution/src/responder.rs b/polkadot/node/network/availability-distribution/src/responder.rs index 6704de72a8..d3828f422e 100644 --- a/polkadot/node/network/availability-distribution/src/responder.rs +++ b/polkadot/node/network/availability-distribution/src/responder.rs @@ -64,11 +64,11 @@ pub async fn answer_request( where Context: SubsystemContext, { - let mut span = jaeger::candidate_hash_span(&req.payload.candidate_hash, "answer-request"); - span.add_stage(jaeger::Stage::AvailabilityDistribution); - let _child_span = span.child_builder("answer-chunk-request") - .with_chunk_index(req.payload.index.0) - .build(); + let span = jaeger::Span::new(req.payload.candidate_hash, "answer-request") + .with_stage(jaeger::Stage::AvailabilityDistribution); + + let _child_span = span.child("answer-chunk-request") + .with_chunk_index(req.payload.index.0); let chunk = query_chunk(ctx, req.payload.candidate_hash, req.payload.index).await?; diff --git a/polkadot/node/network/availability-recovery/src/lib.rs b/polkadot/node/network/availability-recovery/src/lib.rs index 69ebdd5f08..2850a502a6 100644 --- a/polkadot/node/network/availability-recovery/src/lib.rs +++ b/polkadot/node/network/availability-recovery/src/lib.rs @@ -665,8 +665,8 @@ async fn handle_recover( ) -> error::Result<()> { let candidate_hash = receipt.hash(); - let mut span = jaeger::candidate_hash_span(&candidate_hash, "availbility-recovery"); - span.add_stage(jaeger::Stage::AvailabilityRecovery); + let span = jaeger::Span::new(candidate_hash, "availbility-recovery") + .with_stage(jaeger::Stage::AvailabilityRecovery); if let Some(result) = state.availability_lru.get(&candidate_hash) { if let Err(e) = response_sender.send(result.clone()) { diff --git a/polkadot/node/network/bitfield-distribution/src/lib.rs b/polkadot/node/network/bitfield-distribution/src/lib.rs index 84ebc809ed..6c10c64910 100644 --- a/polkadot/node/network/bitfield-distribution/src/lib.rs +++ b/polkadot/node/network/bitfield-distribution/src/lib.rs @@ -400,11 +400,10 @@ where }; let mut _span = job_data.span - .child_builder("msg-received") + .child("msg-received") .with_peer_id(&origin) .with_claimed_validator_index(message.signed_availability.validator_index()) - .with_stage(jaeger::Stage::BitfieldDistribution) - .build(); + .with_stage(jaeger::Stage::BitfieldDistribution); let validator_set = &job_data.validator_set; if validator_set.is_empty() { diff --git a/polkadot/node/network/collator-protocol/src/collator_side.rs b/polkadot/node/network/collator-protocol/src/collator_side.rs index 80c7576f43..15aa51ec03 100644 --- a/polkadot/node/network/collator-protocol/src/collator_side.rs +++ b/polkadot/node/network/collator-protocol/src/collator_side.rs @@ -505,7 +505,7 @@ async fn process_msg( DistributeCollation(receipt, pov, result_sender) => { let _span1 = state.span_per_relay_parent .get(&receipt.descriptor.relay_parent).map(|s| s.child("distributing-collation")); - let _span2 = jaeger::pov_span(&pov, "distributing-collation"); + let _span2 = jaeger::Span::new(&pov, "distributing-collation"); match state.collating_on { Some(id) if receipt.descriptor.para_id != id => { // If the ParaId of a collation requested to be distributed does not match diff --git a/polkadot/node/network/collator-protocol/src/validator_side.rs b/polkadot/node/network/collator-protocol/src/validator_side.rs index 4f5daa9ec4..8965dbdaaf 100644 --- a/polkadot/node/network/collator-protocol/src/validator_side.rs +++ b/polkadot/node/network/collator-protocol/src/validator_side.rs @@ -331,9 +331,8 @@ where from_collator: response_recv.boxed().fuse(), to_requester: result, span: state.span_per_relay_parent.get(&relay_parent).map(|s| { - s.child_builder("collation-request") + s.child("collation-request") .with_para_id(para_id) - .build() }), }; @@ -695,7 +694,7 @@ where ); // Actual sending: - let _span = jaeger::pov_span(&pov, "received-collation"); + let _span = jaeger::Span::new(&pov, "received-collation"); let (mut tx, _) = oneshot::channel(); std::mem::swap(&mut tx, &mut (per_req.to_requester)); let result = tx.send((receipt, pov)); @@ -1116,7 +1115,7 @@ mod tests { AllMessages::NetworkBridge(NetworkBridgeMessage::SendRequests(reqs, IfDisconnected::ImmediateError) ) => { let req = reqs.into_iter().next() - .expect("There should be exactly one request"); + .expect("There should be exactly one request"); match req { Requests::CollationFetching(req) => { let payload = req.payload; @@ -1145,7 +1144,7 @@ mod tests { AllMessages::NetworkBridge(NetworkBridgeMessage::SendRequests(reqs, IfDisconnected::ImmediateError) ) => { let req = reqs.into_iter().next() - .expect("There should be exactly one request"); + .expect("There should be exactly one request"); match req { Requests::CollationFetching(req) => { let payload = req.payload; diff --git a/polkadot/node/network/pov-distribution/src/lib.rs b/polkadot/node/network/pov-distribution/src/lib.rs index 585cdcf9e8..20f27b3693 100644 --- a/polkadot/node/network/pov-distribution/src/lib.rs +++ b/polkadot/node/network/pov-distribution/src/lib.rs @@ -154,9 +154,8 @@ async fn handle_signal( let _timer = state.metrics.time_handle_signal(); for (relay_parent, span) in activated { - let _span = span.child_builder("pov-dist") - .with_stage(jaeger::Stage::PoVDistribution) - .build(); + let _span = span.child("pov-dist") + .with_stage(jaeger::Stage::PoVDistribution); match request_validators_ctx(relay_parent, ctx).await { Ok(vals_rx) => { diff --git a/polkadot/node/network/statement-distribution/src/lib.rs b/polkadot/node/network/statement-distribution/src/lib.rs index 35bdba3e42..2196bd43e6 100644 --- a/polkadot/node/network/statement-distribution/src/lib.rs +++ b/polkadot/node/network/statement-distribution/src/lib.rs @@ -517,10 +517,9 @@ async fn circulate_statement_and_dependents( None => return, }; - let _span = active_head.span.child_builder("circulate-statement") - .with_candidate(&statement.payload().candidate_hash()) - .with_stage(jaeger::Stage::StatementDistribution) - .build(); + let _span = active_head.span.child("circulate-statement") + .with_candidate(statement.payload().candidate_hash()) + .with_stage(jaeger::Stage::StatementDistribution); // First circulate the statement directly to all peers needing it. // The borrow of `active_head` needs to encompass only this (Rust) statement. @@ -539,9 +538,8 @@ async fn circulate_statement_and_dependents( if let Some((candidate_hash, peers_needing_dependents)) = outputs { for peer in peers_needing_dependents { if let Some(peer_data) = peers.get_mut(&peer) { - let _span_loop = _span.child_builder("to-peer") - .with_peer_id(&peer) - .build(); + let _span_loop = _span.child("to-peer") + .with_peer_id(&peer); // defensive: the peer data should always be some because the iterator // of peers is derived from the set of peers. send_statements_about( @@ -702,10 +700,9 @@ async fn handle_incoming_message<'a>( }; let candidate_hash = statement.payload().candidate_hash(); - let handle_incoming_span = active_head.span.child_builder("handle-incoming") - .with_candidate(&candidate_hash) - .with_peer_id(&peer) - .build(); + let handle_incoming_span = active_head.span.child("handle-incoming") + .with_candidate(candidate_hash) + .with_peer_id(&peer); // check the signature on the statement. if let Err(()) = check_statement_signature(&active_head, relay_parent, &statement) { diff --git a/polkadot/node/overseer/src/lib.rs b/polkadot/node/overseer/src/lib.rs index 906e8ff909..8fef61948c 100644 --- a/polkadot/node/overseer/src/lib.rs +++ b/polkadot/node/overseer/src/lib.rs @@ -2011,7 +2011,7 @@ where } } - let mut span = jaeger::hash_span(hash, "leaf-activated"); + let mut span = jaeger::Span::new(*hash, "leaf-activated"); if let Some(parent_span) = parent_hash.and_then(|h| self.span_per_active_leaf.get(&h)) { span.add_follows_from(&*parent_span);