open-telemetry / open-telemetry/opentelemetry-python

Prometheus exporter should handle metric label key collisions

Open
#3,928 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug exporters prometheus
Dominant language
Python
Stars
2.6k
Forks
1k
Avg merge
4d 15h
Merged PRs (30d)
19

Description

As described in the spec

Metrics from OpenTelemetry with unsupported Attribute names MUST replace invalid characters with the _ character. Multiple consecutive _ characters MUST be replaced with a single _ character. This may cause ambiguity in scenarios where multiple similar-named attributes share invalid characters at the same location. In such unlikely cases, if multiple key-value pairs are converted to have the same Prometheus key, the values MUST be concatenated together, separated by ;, and ordered by the lexicographical order of the original keys.

Right now this is not happening. The following code

counter = meter_provider.get_meter("scope").create_counter(
    "test_with_collision"
)
counter.add(1, {"hello_world": "hello_world", "hello.world": "hello.world"})

expected

# HELP test_with_collision_total 
# TYPE test_with_collision_total counter
test_with_collision_total{hello_world="hello.world;hello_world"} 1.0

actual

# HELP test_with_collision_total My description
# TYPE test_with_collision_total counter
test_with_collision_total{hello_world="hello_world"} 1.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Prometheus exporter path that converts metric attribute names, then reproduce the collision using the counter example in the issue. Done means colliding keys produce one label whose values are concatenated with ; in lexicographical order, matching the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
prometheus, python
Domain
observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.