Skip to content

Commit 53a919f

Browse files
committed
Add more instrumentation
1 parent f62b7d2 commit 53a919f

File tree

8 files changed

+408
-51
lines changed

8 files changed

+408
-51
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

linera-chain/src/chain.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use linera_views::{
3535
views::{ClonableView, CryptoHashView, RootView, View},
3636
};
3737
use serde::{Deserialize, Serialize};
38+
use tracing::instrument;
3839

3940
use crate::{
4041
block::{Block, ConfirmedBlock},
@@ -309,6 +310,12 @@ pub struct ChainTipState {
309310
impl ChainTipState {
310311
/// Checks that the proposed block is suitable, i.e. at the expected height and with the
311312
/// expected parent.
313+
#[instrument(target = "telemetry_only", skip_all, fields(
314+
next_block_height = %self.next_block_height,
315+
block_hash = ?self.block_hash,
316+
proposed_height = %new_block.height,
317+
proposed_previous_hash = ?new_block.previous_block_hash
318+
))]
312319
pub fn verify_block_chaining(&self, new_block: &ProposedBlock) -> Result<(), ChainError> {
313320
ensure!(
314321
new_block.height == self.next_block_height,
@@ -326,6 +333,10 @@ impl ChainTipState {
326333

327334
/// Returns `true` if the validated block's height is below the tip height. Returns an error if
328335
/// it is higher than the tip.
336+
#[instrument(target = "telemetry_only", skip_all, fields(
337+
next_block_height = %self.next_block_height,
338+
height = %height
339+
))]
329340
pub fn already_validated_block(&self, height: BlockHeight) -> Result<bool, ChainError> {
330341
ensure!(
331342
self.next_block_height >= height,
@@ -391,6 +402,10 @@ where
391402
self.context().extra().chain_id()
392403
}
393404

405+
#[instrument(target = "telemetry_only", skip_all, fields(
406+
chain_id = %self.chain_id(),
407+
next_block_height = %self.tip_state.get().next_block_height
408+
))]
394409
pub async fn query_application(
395410
&mut self,
396411
local_time: Timestamp,
@@ -408,6 +423,10 @@ where
408423
.with_execution_context(ChainExecutionContext::Query)
409424
}
410425

426+
#[instrument(target = "telemetry_only", skip_all, fields(
427+
chain_id = %self.chain_id(),
428+
application_id = %application_id
429+
))]
411430
pub async fn describe_application(
412431
&mut self,
413432
application_id: ApplicationId,
@@ -419,6 +438,11 @@ where
419438
.with_execution_context(ChainExecutionContext::DescribeApplication)
420439
}
421440

441+
#[instrument(target = "telemetry_only", skip_all, fields(
442+
chain_id = %self.chain_id(),
443+
target = %target,
444+
height = %height
445+
))]
422446
pub async fn mark_messages_as_received(
423447
&mut self,
424448
target: &ChainId,
@@ -459,6 +483,10 @@ where
459483

460484
/// Returns true if there are no more outgoing messages in flight up to the given
461485
/// block height.
486+
#[instrument(target = "telemetry_only", skip_all, fields(
487+
chain_id = %self.chain_id(),
488+
height = %height
489+
))]
462490
pub fn all_messages_delivered_up_to(&self, height: BlockHeight) -> bool {
463491
tracing::debug!(
464492
"Messages left in {:.8}'s outbox: {:?}",
@@ -506,6 +534,9 @@ where
506534

507535
/// Verifies that this chain is up-to-date and all the messages executed ahead of time
508536
/// have been properly received by now.
537+
#[instrument(target = "telemetry_only", skip_all, fields(
538+
chain_id = %self.chain_id()
539+
))]
509540
pub async fn validate_incoming_bundles(&self) -> Result<(), ChainError> {
510541
let chain_id = self.chain_id();
511542
let pairs = self.inboxes.try_load_all_entries().await?;
@@ -540,6 +571,10 @@ where
540571
/// Returns the height of the highest block we have, plus one. Includes preprocessed blocks.
541572
///
542573
/// The "+ 1" is so that it can be used in the same places as `next_block_height`.
574+
#[instrument(target = "telemetry_only", skip_all, fields(
575+
chain_id = %self.chain_id(),
576+
next_block_height = %self.tip_state.get().next_block_height
577+
))]
543578
pub async fn next_height_to_preprocess(&self) -> Result<BlockHeight, ChainError> {
544579
if let Some(height) = self.preprocessed_blocks.indices().await?.last() {
545580
return Ok(height.saturating_add(BlockHeight(1)));
@@ -567,6 +602,11 @@ where
567602
/// round timeouts.
568603
///
569604
/// Returns `true` if incoming `Subscribe` messages created new outbox entries.
605+
#[instrument(target = "telemetry_only", skip_all, fields(
606+
chain_id = %self.chain_id(),
607+
origin = %origin,
608+
bundle_height = %bundle.height
609+
))]
570610
pub async fn receive_message_bundle(
571611
&mut self,
572612
origin: &ChainId,
@@ -630,6 +670,10 @@ where
630670
}
631671

632672
/// Updates the `received_log` trackers.
673+
#[instrument(target = "telemetry_only", skip_all, fields(
674+
chain_id = %self.chain_id(),
675+
num_trackers = %new_trackers.len()
676+
))]
633677
pub fn update_received_certificate_trackers(
634678
&mut self,
635679
new_trackers: BTreeMap<ValidatorPublicKey, u64>,
@@ -649,6 +693,9 @@ where
649693
}
650694
}
651695

696+
#[instrument(target = "telemetry_only", skip_all, fields(
697+
chain_id = %self.chain_id()
698+
))]
652699
pub fn current_committee(&self) -> Result<(Epoch, &Committee), ChainError> {
653700
self.execution_state
654701
.system
@@ -661,6 +708,10 @@ where
661708
}
662709

663710
/// Removes the incoming message bundles in the block from the inboxes.
711+
#[instrument(target = "telemetry_only", skip_all, fields(
712+
chain_id = %self.chain_id(),
713+
timestamp = %timestamp
714+
))]
664715
pub async fn remove_bundles_from_inboxes(
665716
&mut self,
666717
timestamp: Timestamp,
@@ -750,6 +801,10 @@ where
750801

751802
/// Executes a block: first the incoming messages, then the main operation.
752803
/// Does not update chain state other than the execution state.
804+
#[instrument(target = "telemetry_only", skip_all, fields(
805+
chain_id = %block.chain_id,
806+
block_height = %block.height
807+
))]
753808
#[expect(clippy::too_many_arguments)]
754809
async fn execute_block_inner(
755810
chain: &mut ExecutionStateView<C>,
@@ -859,6 +914,10 @@ where
859914

860915
/// Executes a block: first the incoming messages, then the main operation.
861916
/// Does not update chain state other than the execution state.
917+
#[instrument(target = "telemetry_only", skip_all, fields(
918+
chain_id = %self.chain_id(),
919+
block_height = %block.height
920+
))]
862921
pub async fn execute_block(
863922
&mut self,
864923
block: &ProposedBlock,
@@ -919,6 +978,10 @@ where
919978
/// Applies an execution outcome to the chain, updating the outboxes, state hash and chain
920979
/// manager. This does not touch the execution state itself, which must be updated separately.
921980
/// Returns the set of event streams that were updated as a result of applying the block.
981+
#[instrument(target = "telemetry_only", skip_all, fields(
982+
chain_id = %self.chain_id(),
983+
block_height = %block.inner().inner().header.height
984+
))]
922985
pub async fn apply_confirmed_block(
923986
&mut self,
924987
block: &ConfirmedBlock,
@@ -953,6 +1016,10 @@ where
9531016

9541017
/// Adds a block to `preprocessed_blocks`, and updates the outboxes where possible.
9551018
/// Returns the set of streams that were updated as a result of preprocessing the block.
1019+
#[instrument(target = "telemetry_only", skip_all, fields(
1020+
chain_id = %self.chain_id(),
1021+
block_height = %block.inner().inner().header.height
1022+
))]
9561023
pub async fn preprocess_block(
9571024
&mut self,
9581025
block: &ConfirmedBlock,
@@ -979,6 +1046,10 @@ where
9791046
}
9801047

9811048
/// Verifies that the block is valid according to the chain's application permission settings.
1049+
#[instrument(target = "telemetry_only", skip_all, fields(
1050+
block_height = %block.height,
1051+
num_transactions = %block.transactions.len()
1052+
))]
9821053
fn check_app_permissions(
9831054
app_permissions: &ApplicationPermissions,
9841055
block: &ProposedBlock,
@@ -1021,6 +1092,10 @@ where
10211092
}
10221093

10231094
/// Returns the hashes of all blocks we have in the given range.
1095+
#[instrument(target = "telemetry_only", skip_all, fields(
1096+
chain_id = %self.chain_id(),
1097+
next_block_height = %self.tip_state.get().next_block_height
1098+
))]
10241099
pub async fn block_hashes(
10251100
&self,
10261101
range: impl RangeBounds<BlockHeight>,
@@ -1066,6 +1141,10 @@ where
10661141
/// Updates the outboxes with the messages sent in the block.
10671142
///
10681143
/// Returns the set of all recipients.
1144+
#[instrument(target = "telemetry_only", skip_all, fields(
1145+
chain_id = %self.chain_id(),
1146+
block_height = %block.header.height
1147+
))]
10691148
async fn process_outgoing_messages(
10701149
&mut self,
10711150
block: &Block,
@@ -1157,6 +1236,10 @@ where
11571236
/// Updates the event streams with events emitted by the block if they form a contiguous
11581237
/// sequence (might not be the case when preprocessing a block).
11591238
/// Returns the set of updated event streams.
1239+
#[instrument(target = "telemetry_only", skip_all, fields(
1240+
chain_id = %self.chain_id(),
1241+
block_height = %block.header.height
1242+
))]
11601243
async fn process_emitted_events(
11611244
&mut self,
11621245
block: &Block,

linera-core/src/chain_worker/actor.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ where
176176
{
177177
/// Runs the [`ChainWorkerActor`]. The chain state is loaded when the first request
178178
/// arrives.
179+
#[instrument(target = "telemetry_only", skip_all, fields(chain_id = %chain_id))]
179180
#[expect(clippy::too_many_arguments)]
180181
pub(crate) async fn run(
181182
config: ChainWorkerConfig,
@@ -207,6 +208,7 @@ where
207208
/// Spawns a blocking task to execute the service runtime actor.
208209
///
209210
/// Returns the task handle and the endpoints to interact with the actor.
211+
#[instrument(target = "telemetry_only", skip_all, fields(chain_id = %chain_id))]
210212
async fn spawn_service_runtime_actor(
211213
chain_id: ChainId,
212214
) -> (linera_base::task::Blocking, ServiceRuntimeEndpoint) {
@@ -243,8 +245,9 @@ where
243245

244246
/// Runs the worker until there are no more incoming requests.
245247
#[instrument(
248+
target = "telemetry_only",
246249
skip_all,
247-
fields(chain_id = format!("{:.8}", self.chain_id)),
250+
fields(chain_id = format!("{:.8}", self.chain_id), long_lived_services = %self.config.long_lived_services),
248251
)]
249252
async fn handle_requests(
250253
self,
@@ -276,6 +279,7 @@ where
276279
self.chain_id,
277280
service_runtime_endpoint,
278281
)
282+
.instrument(span.clone())
279283
.await?;
280284

281285
Box::pin(worker.handle_request(request).instrument(span)).await;

0 commit comments

Comments
 (0)