Default masking and exclusion
The SDK automatically masks common sensitive query parameters, headers, and request/response body fields based on built-in patterns. For example, fields namedpassword, token, secret, or headers like Authorization are masked by default.
To reduce noise, the SDK also automatically excludes common static assets and health check endpoints, such as /robots.txt or /healthz.
See the data privacy page for complete lists of default masking and exclusion patterns.
Mask sensitive data
You can extend the default masking rules by providing additional regular expressions via themask_query_params, mask_headers, and mask_body_fields parameters. Patterns are case-insensitive and match anywhere within the name. Use ^ and $ anchors for exact matches.
For more control over request and response body masking, you can provide callback functions via the mask_request_body_callback and mask_response_body_callback parameters. The functions receive the captured request and response data as arguments (see callback arguments below) and should return the masked body as bytes, or None to mask the entire body.
Callback function examples
Callbacks are applied before pattern-based field masking. The returned body is still masked using the default and custom
mask_body_fields patterns.Exclude requests
You can exclude requests from logging using path patterns (regular expressions) via theexclude_paths parameter. Like the masking patterns, these are case-insensitive and match anywhere within the request path. Use ^ and $ anchors for exact matches.
Alternatively, you can provide a callback function with custom exclusion logic via the exclude_callback parameter. The function receives the captured request and response data as arguments (see callback arguments below) and should return True to exclude the request from logging, or False to include it.
Callback function example
Excluded requests won’t be logged, but are still counted in metrics. To exclude endpoints from metrics, you can mark them as excluded in the dashboard.
Callback arguments
Therequest dict passed to callback functions has the following keys:
| Key | Description | Type |
|---|---|---|
timestamp | Unix timestamp of the request. | float |
method | HTTP method of the request. | str |
path | Path of the matched endpoint, if applicable. | str | None |
url | Full URL of the request. | str |
headers | List of key-value pairs representing the request headers. | list[tuple[str, str]] |
size | Size of the request body in bytes. | int | None |
consumer | Identifier of the consumer making the request. | str | None |
body | Raw request body. | bytes | None |
response dict passed to mask_response_body_callback and exclude_callback has the following keys:
| Key | Description | Type |
|---|---|---|
status_code | HTTP status code of the response. | int |
response_time | Time taken to respond to the request in seconds. | float |
headers | List of key-value pairs representing the response headers. | list[tuple[str, str]] |
size | Size of the response body in bytes. | int | None |
body | Raw response body. | bytes | None |