Configuration¶
ObserverConfig controls request selection, output handlers, body capture, and redaction.
Key fields¶
enabled: turn the middleware on or offhandlers: chooseconsoleand/orfilefile_path: required whenfileis enabledlog_format:jsonortextinclude_paths/exclude_paths: route filteringexclude_methods: skip methods such asOPTIONSlog_request_body/log_response_body: capture payloadsmax_body_bytes: cap body capture sizeredact_headers/redact_fields: sensitive-data maskingcorrelation_id_header: header used for request correlation
Path matching¶
Paths are normalized before matching:
api/itemsbecomes/api/items- trailing slashes are removed, except for the root path
include_paths is evaluated first. If the request path does not match any include rule, it is skipped. Then exclude_paths is applied.
Example¶
from fastapi_inspector import ObserverConfig
config = ObserverConfig(
handlers=["console", "file"],
file_path="logs/api.log",
include_paths=["/api"],
exclude_paths=["/api/internal"],
redact_fields={"password", "token"},
)