콘텐츠로 이동

API: Tracker

이 페이지는 사용 가능한 Tracker를 문서화합니다. Tracker는 예외를 검사하여 실패로 간주해야 하는지 여부를 결정하는 역할을 합니다.

Tracker 선택에 대한 개요는 Tracker 컴포넌트 가이드를 참조하십시오.


fluxgate.trackers.All

Bases: TrackerBase

Tracker that matches all exceptions.

Always returns true for any exception, tracking all failures.

Examples:

>>> # Track all exceptions
>>> tracker = All()
>>>
>>> # Track all except ValueError
>>> tracker = All() & ~TypeOf(ValueError)
Note

This is the default behavior when you want to track all exceptions.

__call__

__call__(_exception: Exception) -> bool
Source code in fluxgate/trackers.py
92
93
def __call__(self, _exception: Exception) -> bool:
    return True

fluxgate.trackers.TypeOf

TypeOf(*types: type[Exception])

Bases: TrackerBase

Tracker that matches exceptions by type.

Returns true if the exception is an instance of any of the specified types.

Examples:

>>> # Track connection and timeout errors
>>> tracker = TypeOf(ConnectionError, TimeoutError)
>>>
>>> # Combine with OR
>>> tracker = TypeOf(ValueError) | TypeOf(TypeError)

Parameters:

Name Type Description Default
*types type[Exception]

Exception types to track as failures

()

Raises:

Type Description
ValueError

If no exception types are provided

Source code in fluxgate/trackers.py
115
116
117
118
def __init__(self, *types: type[Exception]) -> None:
    if not types:
        raise ValueError("At least one exception type is required")
    self._types = types

__call__

__call__(exception: Exception) -> bool
Source code in fluxgate/trackers.py
120
121
def __call__(self, exception: Exception) -> bool:
    return isinstance(exception, self._types)

fluxgate.trackers.Custom

Custom(func: Callable[[Exception], bool])

Bases: TrackerBase

Tracker with custom exception matching logic.

Allows arbitrary logic to determine if an exception should be tracked.

Examples:

>>> # Track only 503 errors from httpx
>>> def is_503(e):
...     return isinstance(e, httpx.HTTPStatusError) and e.response.status_code == 503
>>>
>>> tracker = Custom(is_503)

Parameters:

Name Type Description Default
func Callable[[Exception], bool]

Function that takes an exception and returns bool

required
Source code in fluxgate/trackers.py
140
141
def __init__(self, func: Callable[[Exception], bool]) -> None:
    self._func = func

__call__

__call__(exception: Exception) -> bool
Source code in fluxgate/trackers.py
143
144
def __call__(self, exception: Exception) -> bool:
    return self._func(exception)