-
Notifications
You must be signed in to change notification settings - Fork 815
Exemplars not working #932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I tried something like this diff --git a/prometheus_client/exposition.py b/prometheus_client/exposition.py
index deaa6ed..b1f77ce 100644
--- a/prometheus_client/exposition.py
+++ b/prometheus_client/exposition.py
@@ -192,7 +192,11 @@ def generate_latest(registry: CollectorRegistry = REGISTRY) -> bytes:
if line.timestamp is not None:
# Convert to milliseconds.
timestamp = f' {int(float(line.timestamp) * 1000):d}'
- return f'{line.name}{labelstr} {floatToGoString(line.value)}{timestamp}\n'
+
+ exemplar = ''
+ if line.exemplar:
+ exemplar = ' # {' + ','.join(f'{key}="{value}"' for key, value in line.exemplar.labels.items()) + '}'
+ return f'{line.name}{labelstr} {floatToGoString(line.value)}{timestamp}{exemplar}\n'
output = []
for metric in registry.collect(): and it seemed to work. No clue if this is the right way to fix this though.. |
Hello, exemplars are only supported in the OpenMetrics exposition format, not in the basic Prometheus exposition format. If you add the header Note that Prometheus will automatically negotiate to use OpenMetrics. |
Ah, thanks! After restarting Prometheus with Maybe a sentence clarifying this in the "Exemplars" section of the README would help other newbies like me :) |
I am not able to get exemplars working in version 0.17.0. Here is a basic reproduction:
I also tried the text exporter and had the same result.
The text was updated successfully, but these errors were encountered: