Skip to content
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

Prometheus exporter target_info key-value pairs must be string #3676

Closed
kornerc opened this issue Feb 6, 2024 · 0 comments · Fixed by #3659
Closed

Prometheus exporter target_info key-value pairs must be string #3676

kornerc opened this issue Feb 6, 2024 · 0 comments · Fixed by #3659
Labels
bug Something isn't working

Comments

@kornerc
Copy link
Contributor

kornerc commented Feb 6, 2024

Describe your environment
...

Steps to reproduce
Prometheus expects labels to be string key-value pairs.
Currently, the labels are not cast to string for the target_info

Here is a minimal example which causes this problem:

import time

from prometheus_client import start_http_server

from opentelemetry import metrics
from opentelemetry.exporter.prometheus import PrometheusMetricReader
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.resources import SERVICE_NAME, Resource

resource = Resource(attributes={
    SERVICE_NAME: "your-service-name",
    "foo": "bar",
    "hist": 1,
})

start_http_server(port=8000, addr="localhost")
reader = PrometheusMetricReader()
provider = MeterProvider(resource=resource, metric_readers=[reader])
metrics.set_meter_provider(provider)

meter = metrics.get_meter("my.meter.name")

work_counter = meter.create_counter(
    "work.counter", unit="1", description="Counts the amount of work done"
)

while True:
    work_counter.add(1, {"work.type": "Debug"})
    print("doing some work...")
    time.sleep(1)

It raises an exception in the Prometheus client: AttributeError: ("'int' object has no attribute 'replace'", Metric(target, Target metadata, info ... here prometheus_client\openmetrics\exposition.py", line 33, in <listcomp> k, v.replace('\\', r'\\').replace('\n', r'\n').replace('"', r'\"'))

What is the expected behavior?
Find a string representation for the target_info labels as it is done for the other metrics.

What is the actual behavior?
The target_info labels are exported in their original representation (non-strings).

Additional context
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant