PromPHP / prometheus_client_php

Prometheus instrumentation library for PHP applications
https://prometheus.io/docs/concepts/metric_types/
Apache License 2.0
423 stars 93 forks source link

Type issue on bucket values #94

Closed tforesti closed 1 year ago

tforesti commented 2 years ago

Hey,

I think there is an issue, if you try this :

$registry = new \Prometheus\CollectorRegistry(new Prometheus\Storage\Redis());

$histogram = $registry->getOrRegisterHistogram('test', 'some_histogram', 'it observes', [], [0, 1, 2, 3, 4, 5]);
$histogram->observe(5);

$renderer = new \Prometheus\RenderTextFormat();
$result = $renderer->render($registry->getMetricFamilySamples());

echo $result;

You get PHP Fatal error: Uncaught TypeError: str_replace(): Argument #3 ($subject) must be of type array|string, int given Here src/Prometheus/RenderTextFormat.php(59) Because bucket values are "labelized" and labels values are "sanitized".

I found a workaround :

$histogram = $registry->getOrRegisterHistogram('test', 'some_histogram', 'it observes', [], ['0', '1', '2', '3', '4', '5']);

But I think it is not the way it should work, am I right ?

joec4i commented 2 years ago

Hi @tforesti I think this was fixed in https://github.com/PromPHP/prometheus_client_php/pull/17 .

tforesti commented 1 year ago

Hi, yes it actually seems to be OK, I probably made a mistake with versions, sorry!