Class Counter.Builder

Enclosing class:
Counter

public static class Counter.Builder extends MetricWithFixedMetadata.Builder<Counter.Builder,Counter>
  • Field Details

    • exemplarsEnabled

      @Nullable protected Boolean exemplarsEnabled
    • exemplarLabelsSupplier

      @Nullable protected Supplier<io.prometheus.metrics.model.snapshots.Labels> exemplarLabelsSupplier
  • Method Details

    • name

      public Counter.Builder name(String name)
      The _total suffix will automatically be appended if it's missing.
      
       Counter c1 = Counter.builder()
           .name("events_total")
           .build();
       Counter c2 = Counter.builder()
           .name("events")
           .build();
       
      In the example above both c1 and c2 would be named "events_total" in Prometheus.

      Throws an IllegalArgumentException if MetricMetadata.isValidMetricName(name) is false.

      Overrides:
      name in class MetricWithFixedMetadata.Builder<Counter.Builder,Counter>
    • build

      public Counter build()
      Specified by:
      build in class MetricWithFixedMetadata.Builder<Counter.Builder,Counter>
    • self

      protected Counter.Builder self()
      Specified by:
      self in class MetricWithFixedMetadata.Builder<Counter.Builder,Counter>
    • exemplarLabelsSupplier

      public Counter.Builder exemplarLabelsSupplier(Supplier<io.prometheus.metrics.model.snapshots.Labels> supplier)
      Provide additional labels to be merged into every automatically-sampled exemplar of this metric. The supplier is called each time an exemplar is sampled, so it can return dynamic values (e.g. a request-scoped identifier from a thread-local). The supplier is only invoked when a valid, sampled span context is present; it has no effect when tracing is not active.

      For a global supplier that applies to all metrics (including metrics registered by third-party libraries you do not control), see ExemplarLabelsSupplier. When both are configured, this per-metric supplier takes precedence over the global one on a label-name collision, and the reserved trace_id/span_id labels always win over both. Labels that collide are silently dropped.

    • withExemplars

      public Counter.Builder withExemplars()
      Allow Exemplars for this metric.
    • withoutExemplars

      public Counter.Builder withoutExemplars()
      Turn off Exemplars for this metric.
    • toProperties

      protected io.prometheus.metrics.config.MetricsProperties toProperties()
      Override if there are more properties than just exemplars enabled.
    • getDefaultProperties

      public io.prometheus.metrics.config.MetricsProperties getDefaultProperties()
      Override if there are more properties than just exemplars enabled.