autometrics-dev / autometrics-py

Easily add metrics to your code that actually help you spot and debug issues in production. Built on Prometheus and OpenTelemetry.
https://autometrics.dev
Apache License 2.0
214 stars 7 forks source link

Ability to define 'ok' versus 'error' results #45

Closed brettimus closed 1 year ago

brettimus commented 1 year ago

If an error response from an HTTP handler is, e.g., a 400, we might not want to count that as an "error" in our metrics.

We should support an additional param to the decorator that accepts a predicate function that returns true if an error result should be an error.

Example


def treat_401_as_ok(exception: Exception):
  if exception instanceof(HTTPError):
    return  exception.response.status_code != 401

@autometrics(error_handler=treat_401_as_ok)
def my_tracked_function():
  ...

Rust: https://github.com/autometrics-dev/autometrics-rs/pull/61