Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

approval-distribution: Add approvals/assignments spans on all paths #7317

Merged
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
13 changes: 12 additions & 1 deletion node/jaeger/src/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl Span {
}

/// Derive a child span from `self`.
pub fn child(&self, name: &'static str) -> Self {
pub fn child(&self, name: &str) -> Self {
alexggh marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could still be static if you use match / if let when creating the span.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it can be static, but it doesn't makes sense to be starting here since inner.child doesn't have this restriction.

match self {
Self::Enabled(inner) => Self::Enabled(inner.child(name)),
Self::Disabled => Self::Disabled,
Expand All @@ -297,11 +297,22 @@ impl Span {
self
}

/// Attach a peer-id tag to the span.
#[inline(always)]
pub fn with_peer_id(self, peer: &PeerId) -> Self {
self.with_string_tag("peer-id", &peer.to_base58())
}

/// Attach a `peer-id` tag to the span when peer is present.
#[inline(always)]
pub fn with_optional_peer_id(self, peer: Option<&PeerId>) -> Self {
if let Some(peer) = peer {
self.with_peer_id(peer)
} else {
self
}
}

/// Attach a candidate hash to the span.
#[inline(always)]
pub fn with_candidate(self, candidate_hash: CandidateHash) -> Self {
Expand Down
46 changes: 30 additions & 16 deletions node/network/approval-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,21 @@ impl State {
) where
R: CryptoRng + Rng,
{
let _span = self
.spans
.get(&assignment.block_hash)
.map(|span| {
span.child(if source.peer_id().is_some() {
"peer-import-and-distribute-assignment"
} else {
"local-import-and-distribute-assignment"
})
})
.unwrap_or_else(|| jaeger::Span::new(&assignment.block_hash, "distribute-assignment"))
.with_string_tag("block-hash", format!("{:?}", assignment.block_hash))
.with_optional_peer_id(source.peer_id().as_ref())
.with_stage(jaeger::Stage::ApprovalDistribution);

let block_hash = assignment.block_hash;
let validator_index = assignment.validator;

Expand Down Expand Up @@ -985,6 +1000,21 @@ impl State {
source: MessageSource,
vote: IndirectSignedApprovalVote,
) {
let _span = self
.spans
.get(&vote.block_hash)
.map(|span| {
span.child(if source.peer_id().is_some() {
"peer-import-and-distribute-approval"
} else {
"local-import-and-distribute-approval"
})
})
.unwrap_or_else(|| jaeger::Span::new(&vote.block_hash, "distribute-approval"))
.with_string_tag("block-hash", format!("{:?}", vote.block_hash))
.with_optional_peer_id(source.peer_id().as_ref())
.with_stage(jaeger::Stage::ApprovalDistribution);

let block_hash = vote.block_hash;
let validator_index = vote.validator;
let candidate_index = vote.candidate_index;
Expand Down Expand Up @@ -1724,14 +1754,6 @@ impl ApprovalDistribution {
state.handle_new_blocks(ctx, metrics, metas, rng).await;
},
ApprovalDistributionMessage::DistributeAssignment(cert, candidate_index) => {
let _span = state
.spans
.get(&cert.block_hash)
.map(|span| span.child("import-and-distribute-assignment"))
.unwrap_or_else(|| jaeger::Span::new(&cert.block_hash, "distribute-assignment"))
.with_string_tag("block-hash", format!("{:?}", cert.block_hash))
.with_stage(jaeger::Stage::ApprovalDistribution);

gum::debug!(
target: LOG_TARGET,
"Distributing our assignment on candidate (block={}, index={})",
Expand All @@ -1751,14 +1773,6 @@ impl ApprovalDistribution {
.await;
},
ApprovalDistributionMessage::DistributeApproval(vote) => {
let _span = state
.spans
.get(&vote.block_hash)
.map(|span| span.child("import-and-distribute-approval"))
.unwrap_or_else(|| jaeger::Span::new(&vote.block_hash, "distribute-approval"))
.with_string_tag("block-hash", format!("{:?}", vote.block_hash))
.with_stage(jaeger::Stage::ApprovalDistribution);

gum::debug!(
target: LOG_TARGET,
"Distributing our approval vote on candidate (block={}, index={})",
Expand Down