@Override
  public Stream<Observation> streamObservations() {
    final var snapshot = histogram.collect();
    return snapshot.getDataPoints().stream()
        .flatMap(
            dataPoint -> {
              if (!dataPoint.hasClassicHistogramData()) {
                throw new IllegalStateException("Only classic histogram are supported");
              }

              final var labelValues = getLabelValues(dataPoint.getLabels());
              final var classicBuckets = dataPoint.getClassicBuckets();
              final var observations = new ArrayList<Observation>(classicBuckets.size() + 2);

              if (dataPoint.hasSum()) {
                observations.add(
                    new Observation(
                        category, name, dataPoint.getSum(), addLabelValues(labelValues, "sum")));
              }

              if (dataPoint.hasCount()) {
                observations.add(
                    new Observation(
                        category,
                        name,
                        dataPoint.getCount(),
                        addLabelValues(labelValues, "count")));
              }

              classicBuckets.stream()
                  .forEach(
                      bucket ->
                          observations.add(
                              new Observation(
                                  category,
                                  name,
                                  bucket.getCount(),
                                  addLabelValues(
                                      labelValues,
                                      "bucket",
                                      Double.toString(bucket.getUpperBound())))));

              return observations.stream();
            });
  }
Abstract base class for Prometheus histogram collectors. A histogram samples durations and counts
them in configurable buckets. * It also provides a sum of all observed values.
metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/AbstractPrometheusHistogram.java