Otlp circuit
provide.foundation.integrations.openobserve.otlp_circuit
¶
TODO: Add module docstring.
Classes¶
OTLPCircuitBreaker
¶
OTLPCircuitBreaker(
failure_threshold: int = 5,
timeout: float = 60.0,
half_open_timeout: float = 10.0,
)
Circuit breaker for OTLP connections with exponential backoff.
States
- closed: Normal operation, requests allowed
- open: Too many failures, requests blocked
- half_open: Testing if service recovered
Examples:
>>> breaker = OTLPCircuitBreaker(failure_threshold=3, timeout=60.0)
>>> if breaker.can_attempt():
... success = send_otlp_log()
... if success:
... breaker.record_success()
... else:
... breaker.record_failure()
Initialize circuit breaker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
failure_threshold
|
int
|
Number of failures before opening circuit |
5
|
timeout
|
float
|
Seconds to wait before attempting half-open (doubles each time) |
60.0
|
half_open_timeout
|
float
|
Seconds to wait in half-open before trying again |
10.0
|
Source code in provide/foundation/integrations/openobserve/otlp_circuit.py
Attributes¶
Functions¶
can_attempt
¶
Check if we can attempt an OTLP operation.
Returns:
| Type | Description |
|---|---|
bool
|
True if operation should be attempted, False if circuit is open |
Source code in provide/foundation/integrations/openobserve/otlp_circuit.py
get_stats
¶
Get circuit breaker statistics.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with current state and statistics |
Source code in provide/foundation/integrations/openobserve/otlp_circuit.py
record_failure
¶
Record a failed operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
Exception | None
|
Optional exception that caused the failure |
None
|
Source code in provide/foundation/integrations/openobserve/otlp_circuit.py
record_success
¶
Record a successful operation.
Source code in provide/foundation/integrations/openobserve/otlp_circuit.py
reset
¶
Manually reset the circuit breaker to closed state.
Source code in provide/foundation/integrations/openobserve/otlp_circuit.py
Functions¶
get_otlp_circuit_breaker
¶
Get the global OTLP circuit breaker instance.
Returns:
| Type | Description |
|---|---|
OTLPCircuitBreaker
|
Shared OTLPCircuitBreaker instance |
Source code in provide/foundation/integrations/openobserve/otlp_circuit.py
reset_otlp_circuit_breaker
¶
Reset the global circuit breaker (primarily for testing).