Skip to content

Conversation

@awatts73
Copy link

Add Build Info as Labeled Prometheus Gauge Metrics

Exposes snarkOS build information as Prometheus gauge metrics with labels, following the "info" metric best practices.

Implementation

Creates labeled gauge metrics for:

  • Version: built_info::PKG_VERSION
  • Git Commit: built_info::GIT_COMMIT_HASH
  • Git Branch: built_info::GIT_HEAD_REF
  • Features: built_info::FEATURES_LOWERCASE_STR

Metrics Output

# TYPE snarkos_build_info gauge
snarkos_build_info{version="4.2.1"} 1
snarkos_build_info{git_commit="f2e3c3fa3708d527d1f20ddd418c08db81a1620a"} 1  
snarkos_build_info{git_branch="feat/add_buildinfo_to_metrics"} 1
snarkos_build_info{features="default,rayon"} 1

Technical Details

  • Uses native ::metrics::gauge! macro with labels
  • Follows same pattern as snarkVM's histogram_label
  • Automatically initialized when metrics are enabled
  • Static build info set once at startup

Changes

  • Added build script (build.rs) for compile-time build information
  • Added metrics dependency (v0.22) for labeled gauge support
  • Updated metric names in names.rs
  • Implemented gauge metrics with labels in lib.rs

Benefits

  • Track version distribution across deployments
  • Correlate metrics with specific code changes
  • Verify deployments via metrics scraping

pub const TCP_TASKS: &str = "snarkos_tcp_tasks_total";
}

pub mod build {
Copy link
Collaborator

@vicsn vicsn Sep 16, 2025

Choose a reason for hiding this comment

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

Should this be added to GAUGE_NAMES above?

I think for this PR, manual testing should suffice. If you haven't checked the endpoint already, can you run the top level devnet.sh script from this repo, query the :5000/metrics endpoint, and see if the build info shows up as expected?

I can hear you thinking that we should also have tests to prevent unexpected changes to our API endpoints, it is on the roadmap, and will be tracking how the explorer designs and implements these tests.

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.

3 participants