prometheus / prometheus/client_python

OpenMetrics support for textfile collector

Open
#957 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.4k
Forks
876
Avg merge
8d 4h
Merged PRs (30d)
1

Description

Currently prometheus_client.exposition.write_to_textfile doesn't support the OpenMetrics text format, which I'm addressing with this (private) hack:

from prometheus_client.openmetrics.exposition import (
    generate_latest as generate_latest_openmetrics,
)
from prometheus_client.registry import CollectorRegistry

def write_openmetrics_to_textfile(path: str, registry: CollectorRegistry) -> None:
    """
    Fork of `prometheus_client.exposition.write_to_textfile`, as the project
    didn't provide an OpenMetrics variant of this helper function.
    """
    with open(path, "wb") as fp:
        fp.write(generate_latest_openmetrics(registry))

Would your project be interested in a non-hacky (as is the case above) OpenMetrics support for textfile collector?

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 at prometheus_client.exposition.write_to_textfile and compare its behavior with prometheus_client.openmetrics.exposition.generate_latest. Determine how the helper should expose OpenMetrics output while preserving the existing textfile collector behavior. Done means the supported helper writes valid OpenMetrics text for the provided registry and is covered by the project's relevant tests.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.