Processor
provide.foundation.logger.ratelimit.processor
¶
TODO: Add module docstring.
Classes¶
RateLimiterProcessor
¶
RateLimiterProcessor(
emit_warning_on_limit: bool = True,
warning_interval_seconds: float = 60.0,
summary_interval_seconds: float = 5.0,
)
Structlog processor that applies rate limiting to log messages. Can be configured with global and per-logger rate limits.
Initialize the rate limiter processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emit_warning_on_limit
|
bool
|
Whether to emit a warning when rate limited |
True
|
warning_interval_seconds
|
float
|
Minimum seconds between rate limit warnings |
60.0
|
summary_interval_seconds
|
float
|
Interval for rate limit summary reports |
5.0
|
Source code in provide/foundation/logger/ratelimit/processor.py
Functions¶
__call__
¶
Process a log event, applying rate limiting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Any
|
The logger instance |
required |
method_name
|
str
|
The log method name (debug, info, etc.) |
required |
event_dict
|
EventDict
|
The event dictionary |
required |
Returns:
| Type | Description |
|---|---|
EventDict
|
The event dictionary if allowed, or raises DropEvent if rate limited |
Source code in provide/foundation/logger/ratelimit/processor.py
Functions¶
create_rate_limiter_processor
¶
create_rate_limiter_processor(
global_rate: float | None = None,
global_capacity: float | None = None,
per_logger_rates: (
dict[str, tuple[float, float]] | None
) = None,
emit_warnings: bool = True,
summary_interval: float = 5.0,
max_queue_size: int = 1000,
max_memory_mb: float | None = None,
overflow_policy: str = "drop_oldest",
) -> RateLimiterProcessor
Factory function to create and configure a rate limiter processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
global_rate
|
float | None
|
Global logs per second limit |
None
|
global_capacity
|
float | None
|
Global burst capacity |
None
|
per_logger_rates
|
dict[str, tuple[float, float]] | None
|
Dict of logger_name -> (rate, capacity) tuples |
None
|
emit_warnings
|
bool
|
Whether to emit warnings when rate limited |
True
|
summary_interval
|
float
|
Seconds between rate limit summary reports |
5.0
|
max_queue_size
|
int
|
Maximum queue size when buffering |
1000
|
max_memory_mb
|
float | None
|
Maximum memory for buffered logs |
None
|
overflow_policy
|
str
|
Policy when queue is full |
'drop_oldest'
|
Returns:
| Type | Description |
|---|---|
RateLimiterProcessor
|
Configured RateLimiterProcessor instance |