'Why Prometheus counters and gauges in Java need to be static?

I see in the documentation that the counters and gauges are initialized as static members: https://github.com/prometheus/client_java#counter

import io.prometheus.client.Counter;
class YourClass {
  static final Counter requests = Counter.build()
     .name("requests_total").help("Total requests.").register();

  void processRequest() {
    requests.inc();
    // Your code here.
  }
}

I cannot find any information why. Is there any specific reason for this? Or is it just to make it uniform with loggers?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source