Skip to content

'Counter' object has no attribute '_value' #454

Closed

Description

@AlexPadron

Hi all,

I'm running into an issue when creating an exception counter out of a standard counter without passing label names. Specifically, it does not provide an informative error if a user incorrectly passes labels when calling count_exceptions. Code to replicate:

from prometheus_client import Counter


c = Counter('counter', documentation='A sample counter', labelnames=('label',))

with c.count_exceptions():
    raise RuntimeError('panic!')

Expected behavior: c.count_exceptions() should raise an informative error message because the incorrect labels are passed.

Actual behavior: AttributeError: 'Counter' object has no attribute '_value' occurs when the exception is raised, because we are trying to increment an non observable metric.

Proposed fix: Check self._is_observable() in the count_exceptions method, and raise an error if the user is constructing an ExceptionCounter out of a non observable Counter.

Activity

  1. brian-brazil commented on Aug 19, 2019

    @brian-brazil
    Contributor

    Do you want to send a PR?

  2. AlexPadron commented on Aug 19, 2019

    @AlexPadron
    ContributorAuthor

    sure!

  3. AlexPadron commented on Aug 19, 2019

    @AlexPadron
    ContributorAuthor

    I think I need access to the repo, not currently able to push to a remote branch

  4. brian-brazil commented on Aug 19, 2019

    @brian-brazil
    Contributor

    Fork it in github, and push your branch there.

  5. AlexPadron commented on Aug 19, 2019

    @AlexPadron
    ContributorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions