prometheus / prometheus/client_python

Async context manager

Open
#535 12 comments 8 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

Usecase:

c = Counter("errors_count")

@c.count_exceptions()
def foo():  # counter = 1
      raise Exception()

@c.count_exceptions()
async def foo_async(): # counter still 1
      await sleep(1)
      raise Exception()

Quick search in project did nothing to me.

It would be cool if counter (and other objects) would handle this right out of the box, especially if we're talking about metrics for web world.

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 by tracing the Counter implementation and its count_exceptions() decorator, then inspect how the example behaves for foo_async. Define the supported async context-manager or decorator behavior and verify that exceptions from the async example update the counter as requested.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.