Metrics
Optional internal metrics for observability.
Enabling
Set core.enable_metrics=True (env: FAPILOG_CORE__ENABLE_METRICS=true). Metrics are recorded asynchronously; exporting is left to the application.
What is recorded
Events submitted/dropped
Queue high-watermark
Backpressure waits
Flush latency (per batch)
Sink errors
Priority queue evictions and drops
Prometheus Metrics Reference
Metric |
Type |
Labels |
Description |
|---|---|---|---|
|
Counter |
- |
Events successfully enqueued |
|
Counter |
|
Events dropped due to backpressure |
|
Counter |
- |
Events processed by workers |
|
Gauge |
- |
Maximum queue depth observed |
|
Counter |
- |
Times backpressure was applied |
|
Histogram |
- |
Batch flush latency |
|
Histogram |
- |
Events per batch |
|
Counter |
|
Sink write failures |
|
Counter |
- |
Evictions triggered by protected events |
|
Counter |
|
Events evicted by log level |
|
Counter |
- |
Total fields masked by redactors |
|
Counter |
- |
Policy violation flags from field_blocker |
|
Counter |
- |
Fields logged via |
|
Counter |
- |
Redaction pipeline exceptions |
Priority Queue Metrics
When using protected levels (default: ERROR, CRITICAL, FATAL), the queue tracks priority-based behavior:
# Priority protection effectiveness - how often eviction saved protected events
rate(fapilog_priority_evictions_total[5m])
# Protected events we failed to save (queue saturated with protected events)
rate(fapilog_events_dropped_total{protected="true"}[5m])
# What levels are being sacrificed to save errors?
topk(5, rate(fapilog_events_evicted_total[5m])) by (level)
# Ratio of protected vs unprotected drops
rate(fapilog_events_dropped_total{protected="true"}[5m])
/ rate(fapilog_events_dropped_total[5m])
Alerting on Protection Failures
# Alert when protected events are being dropped (queue saturated)
- alert: FapilogProtectedEventsDropped
expr: rate(fapilog_events_dropped_total{protected="true"}[5m]) > 0
for: 1m
labels:
severity: critical
annotations:
summary: "Protected log events being dropped - queue saturated"
Redaction Metrics
Redaction operational metrics are recorded automatically when core.enable_metrics=True. These counters track masking activity, policy enforcement, and pipeline health.
Metric |
What It Tracks |
|---|---|
|
Fields masked by any redactor (field_mask, regex_mask, string_truncate, etc.) |
|
Fields blocked by |
|
Fields declared via |
|
Unexpected exceptions in the redaction pipeline |
PromQL Examples
# Redaction activity rate
rate(fapilog_redacted_fields_total[5m])
# Policy violations — are developers logging blocked fields?
rate(fapilog_policy_violations_total[5m])
# Sensitive container adoption — are developers using sensitive={}?
rate(fapilog_sensitive_fields_total[5m])
# Redaction pipeline health — any exceptions?
rate(fapilog_redaction_exceptions_total[5m])
Alerting on Redaction Issues
# Alert when redaction pipeline is throwing exceptions
- alert: FapilogRedactionExceptions
expr: rate(fapilog_redaction_exceptions_total[5m]) > 0
for: 1m
labels:
severity: warning
annotations:
summary: "Redaction pipeline exceptions detected"
# Alert on high policy violation rate (field_blocker blocking fields)
- alert: FapilogPolicyViolations
expr: rate(fapilog_policy_violations_total[5m]) > 10
for: 5m
labels:
severity: info
annotations:
summary: "High rate of policy violations — review blocked field usage"
System Metrics
System metrics (CPU usage, memory, disk I/O) are provided by the runtime_info enricher when the system extra is installed.
Platform Note: System metrics require
psutil, which is only installed on Linux and macOS. On Windows, system metrics fields will not be populated.# Linux/macOS - psutil installed, system metrics available pip install fapilog[system] # Windows - psutil not installed, system metrics unavailable pip install fapilog[system] # Installs fapilog but not psutil
Usage
from fapilog import Settings, get_logger
settings = Settings(core__enable_metrics=True)
logger = get_logger(settings=settings)
logger.info("metrics enabled")
Expose or scrape metrics from your application using your preferred exporter; fapilog does not start an HTTP metrics server itself.