Skip to content

Commit aa31cc0

Browse files
committed
Include metric name in exception message
Add metric name in the runtime exception message which is thrown when escapeAllLabels fails to combine labels. Signed-off-by: vlahanas <v.lahanas@ferryhopper.com>
1 parent 82e42b5 commit aa31cc0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Prometheus/RenderTextFormat.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private function renderSample(MetricFamilySamples $metric, Sample $sample): stri
4040
{
4141
$labelNames = $metric->getLabelNames();
4242
if ($metric->hasLabelNames() || $sample->hasLabelNames()) {
43-
$escapedLabels = $this->escapeAllLabels($labelNames, $sample);
43+
$escapedLabels = $this->escapeAllLabels($metric, $labelNames, $sample);
4444
return $sample->getName() . '{' . implode(',', $escapedLabels) . '} ' . $sample->getValue();
4545
}
4646
return $sample->getName() . ' ' . $sample->getValue();
@@ -56,19 +56,20 @@ private function escapeLabelValue(string $v): string
5656
}
5757

5858
/**
59+
* @param MetricFamilySamples $metric
5960
* @param string[] $labelNames
6061
* @param Sample $sample
6162
*
6263
* @return string[]
6364
*/
64-
private function escapeAllLabels(array $labelNames, Sample $sample): array
65+
private function escapeAllLabels(MetricFamilySamples $metric, array $labelNames, Sample $sample): array
6566
{
6667
$escapedLabels = [];
6768

6869
$labels = array_combine(array_merge($labelNames, $sample->getLabelNames()), $sample->getLabelValues());
6970

7071
if ($labels === false) {
71-
throw new RuntimeException('Unable to combine labels.');
72+
throw new RuntimeException('Unable to combine labels for metric named ' . $metric->getName());
7273
}
7374

7475
foreach ($labels as $labelName => $labelValue) {

0 commit comments

Comments
 (0)