Skip to main content
from fastapi import FastAPI
from apitally.fastapi import ApitallyMiddleware

app = FastAPI()
app.add_middleware(
    ApitallyMiddleware,
    client_id="your-client-id",
    env="dev",
    enable_request_logging=True,
    # other parameters ...
)
See the setup guides for more examples.

Parameters

The following configuration parameters are available. Only client_id and env are required.
ParameterDescriptionTypeDefault
client_idClient ID for your application. Find it on the Setup instructions page for your app.string
envName of the environment, e.g. prod or dev. The environment will be automatically created if it doesn’t exist.stringdev
app_versionThe current version of your application, e.g. 1.0.0.stringNone
enable_request_loggingWhether request logging is enabled.boolFalse
log_query_paramsWhether to include query parameters in the logs. If disabled, these will be stripped from the request URLs logged.boolTrue
log_request_headersWhether to include request headers in the logs. Default masking for common sensitive headers (e.g. Authorization) applies.boolFalse
log_request_bodyWhether to include the request body in the logs. Only JSON and text are supported, up to 50 KB.boolFalse
log_response_headersWhether to include response headers in the logs.boolTrue
log_response_bodyWhether to include the response body in the logs. Only JSON and text are supported, up to 50 KB.boolFalse
log_exceptionWhether to include exception details in the logs.boolTrue
capture_logsWhether to capture application logs emitted during request handling.boolFalse
capture_tracesWhether to enable tracing with OpenTelemetry.boolFalse
mask_query_paramsList of regular expressions for matching query parameters to mask. These are in addition to the default masking patterns.list[str][]
mask_headersList of regular expressions for matching headers to mask. These are in addition to the default masking patterns.list[str][]
mask_body_fieldsList of regular expressions for matching request/response body fields to mask. These are in addition to the default masking patterns.list[str][]
mask_request_body_callbackCallback function for masking the request body. Takes one parameter request and returns the request body as bytes or None.CallableNone
mask_response_body_callbackCallback function for masking the response body. Takes two parameters request and response and returns the response body as bytes or None.CallableNone
exclude_pathsList of regular expressions for matching paths to exclude from logging.list[str][]
exclude_callbackCallback function for excluding requests from logging. Takes two parameters request and response and returns True, if the request should be excluded, or False otherwise.CallableNone