Skip to content

Conversation

@BentEngbers
Copy link

@BentEngbers BentEngbers commented Dec 30, 2025

I am currently migrating a large project from prometheus to this crate.

Given the high volume of metrics and the variety of tasks in our project, we have opted for a global registry and global metrics. I have modified the examples/axum.rs example to demonstrate this pattern and provide a reference for other users.

  1. Are there any improvements or best practices you would suggest for this example?
  2. Are there potential changes to the library that could better support this specific use case?

Bent Engbers added 5 commits December 30, 2025 16:30
Signed-off-by: Bent Engbers <[email protected]>
Signed-off-by: Bent Engbers <[email protected]>
Signed-off-by: Bent Engbers <[email protected]>
@cormacrelf
Copy link

Are there any improvements or best practices you would suggest for this example?

Well you should note that if you have a LazyLock, and you never increment it, you will never see my_counter 0 in the output due to the lazy init never having needed to run.

I guess if this is a problem you could work around it by using https://docs.rs/inventory to build a global list of &'static reference to metrics that can be registered along with name/description/unit, and iterate that at server startup. Looks very difficult to get the .register function to work, but there is an EncodeMetric trait which could be implemented on LazyLock<T> where T: EncodeMetric or perhaps &'static LazyLock<T>, something like that.

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.

2 participants