bee icon indicating copy to clipboard operation
bee copied to clipboard

Use a build tag to toggle Prometheus/metrics

Open v1rtl opened this issue 5 months ago • 0 comments

Summary

Not always metrics are needed to be enabled. In certain cases, you'd want to have them disabled to decrease bundle size and gain slight performance gains. Would be very nice if all metrics (including both prometheus and API endpoints) could be disabled using a build tag

Motivation

There is no point for Prometheus metrics in WASM or low-end environments such as EFI modules. Additionally, Prometheus blocks compilation for tinygo.

Implementation

Use build tags. Here's an article explaining how they work: https://leapcell.io/blog/understanding-go-build-tags

Example name: -tag metrics

Drawbacks

Would require a bunch of manual rewriting. You can also check whether Prometheus is included or not by running gsa and observing imports: https://github.com/Zxilly/go-size-analyzer/issues

v1rtl avatar Aug 02 '25 13:08 v1rtl