Skip to content

Add canonical tracing attribute encoding - #2509

Merged
Mirko-von-Leipzig merged 2 commits into
nextfrom
mirko/tracing-attributes
Aug 27, 2026
Merged

Add canonical tracing attribute encoding#2509
Mirko-von-Leipzig merged 2 commits into
nextfrom
mirko/tracing-attributes

Conversation

@Mirko-von-Leipzig

@Mirko-von-Leipzig Mirko-von-Leipzig commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Closes #2325

Summary

Adds a new tracing trait RecordAttribute. Recorded fields must implement this trait in order to be recorded (opt-out is possible).

The trait allows a type to define its trace value encoding, as well as the attribute names it allows. This tightens the contract on what key-value fields may assume, I'm hoping this allows us to standardize better.

This PR doesn't migrate to this trait yet; that will come in follow-up stack PRs.

One additional (debateable) detail is that this automatically allows for pluralisation for list-type containers. This is pretty basic; but we can extend the grammar e.g. if T allows transaction.id then &[T] allows transaction.ids.

Changelog

changelog = "none"
reason    = "Internal change only."

@Mirko-von-Leipzig
Mirko-von-Leipzig marked this pull request as ready for review August 24, 2026 09:11
@Mirko-von-Leipzig
Mirko-von-Leipzig marked this pull request as draft August 24, 2026 09:35
@Mirko-von-Leipzig
Mirko-von-Leipzig force-pushed the mirko/tracing-attributes branch 3 times, most recently from cb47702 to d3c0526 Compare August 24, 2026 15:20
Comment on lines +12 to +143
const BOOLEAN_FIELD_NAMES: &[&str] = &[
"account.updated",
"note.erased",
"note.id_resolved",
"panic",
"request.include_mmr_proof",
"request.include_proof",
"rpc.authentication.configured",
];

const NUMBER_FIELD_NAMES: &[&str] = &[
"account.id.length",
"account.index",
"asset.amount",
"batch.expiration_height",
"batch.expires_at",
"batch.reference_block.number",
"batch.size",
"block.from",
"block.number",
"block.protocol.version",
"block.size",
"block.timestamp",
"block_range.from",
"block_range.to",
"counter.failures.consecutive",
"counter.latency.timeout_ms",
"counter.value.expected",
"counter.value.observed",
"counter.value.target",
"current_client_block_height",
"cutoff_block",
"db.account_state_forest.size",
"db.account_tree.size",
"db.block_store.size",
"db.nullifier_tree.size",
"db.sqlite.connection_pool_size",
"db.sqlite.size",
"db.sqlite.wal.size",
"dice_roll",
"failure_rate",
"inputs_size",
"mempool.accounts",
"mempool.batches.proposed",
"mempool.batches.proven",
"mempool.nullifiers",
"mempool.output_notes",
"mempool.transactions.unbatched",
"mempool.transactions.uncommitted",
"note.tag",
"ntx_builder.max_cycles",
"ntx_builder.tx_expiration_delta",
"port",
"pow.hash",
"pow.nonce",
"pow.target",
"pow.target.leading_zero_bits",
"prefix_len",
"proof_size",
"prover.capacity",
"prover.port",
"prover.proof_type.raw",
"reference_block.number",
"retry.attempt",
"retry.delay_ms",
"shutdown.grace_period_ms",
"snapshot.block_num",
"snapshot.lifetime_ms",
"snapshot.superseded_for_ms",
"snapshots.live",
"subscription.idle_ms",
"subscription.stall_timeout_ms",
"sync.block_gap",
"sync.ready_threshold",
"sync.upstream_block",
"timeout.ms",
"tip.number",
"tip.stale_duration_secs",
"transaction.expiration_delta",
"transaction.expires_at",
"transaction.reference_block.number",
"transaction.submitted_at",
"worker.status.raw",
"workers.active",
"workers.capacity",
];

const STRING_FIELD_NAMES: &[&str] = &[
"account.id",
"account.storage.kind",
"account.storage.map.entry.operation",
"account.storage.operation",
"asset.symbol",
"batch.interval",
"block.interval",
"dependency.endpoint",
"dependency.name",
"genesis.source",
"genesis.source.kind",
"internal.listen",
"mempool.removal.reason",
"network_monitor.listen",
"node.role",
"note.execution_cycles",
"ntx_builder.endpoint",
"ntx_builder.idle_timeout",
"ntx_builder.listen",
"operation.name",
"path",
"pow.challenge.prefix",
"prover",
"prover.kind",
"prover.timeout",
"request.kind",
"rpc.endpoint",
"rpc.listen",
"sequencer.endpoint",
"service.name",
"service.version",
"shutdown.signal",
"sync.block_source.endpoint",
"task.name",
"transaction.id",
"transaction.input_notes",
"transaction.output_notes",
"tx_prover.endpoint",
"validator.admin_listen",
"validator.endpoints",
"validator.listen",
"validator.signer",
"worker.name",
];

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This long list of primitives fall primarily into two camps:

  1. Things that should be opt-out/once off so they shouldn't be here, or
  2. things that are named wrong e.g. endpoint/listen etc should probably just be listen.

We should attempt to minimize these going further.

@Mirko-von-Leipzig
Mirko-von-Leipzig marked this pull request as ready for review August 24, 2026 15:30
}

impl RecordAttribute for Path {
const FIELD_NAMES: &'static [&'static str] = &["data.directory", "genesis.file", "path"];

@sergerad sergerad Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This kind of thing feels strange (domain specific language in the utility crate) but the end result is positive.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, its a bit unfortunate, but that's what Rust's orphan rules result in :/

In theory we could new type this, or do something cleverer, but at this point its not super worth it imo. I also move this into a dedicated tracing crate at end-of-stack which may make it slightly less weird.

@kkovaacs kkovaacs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks nice!

@Mirko-von-Leipzig
Mirko-von-Leipzig force-pushed the mirko/tracing-attributes branch from d3c0526 to f2e667f Compare August 27, 2026 13:04
@Mirko-von-Leipzig
Mirko-von-Leipzig merged commit d4cdd88 into next Aug 27, 2026
28 checks passed
@Mirko-von-Leipzig
Mirko-von-Leipzig deleted the mirko/tracing-attributes branch August 27, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve tracing of collections

3 participants