prometheus_client_php icon indicating copy to clipboard operation
prometheus_client_php copied to clipboard

Type issue on bucket values

Open tforesti opened this issue 3 years ago • 0 comments

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 ?

tforesti avatar Jul 13 '22 10:07 tforesti