Skip to main content
The Apitally SDK provides mechanisms for masking sensitive data in captured requests, responses, and application logs.

Default masking

The SDK automatically masks common sensitive query parameters, headers, and request/response body fields based on built-in patterns. For example, fields named password, token, secret, or headers like Authorization are masked by default. See the data privacy page for more information about default masking.

Custom masking

You can extend the default masking rules by providing additional regular expressions via the MaskQueryParams, MaskHeaders, and MaskBodyFields options. Patterns are case-insensitive and match anywhere within the name. Use ^ and $ anchors for exact matches. Body field patterns recursively match keys in JSON objects and replace the corresponding values only when they are strings. The following example uses Gin. The same masking options are available for all supported frameworks.
Gin example

Body masking callbacks

For more control over body masking, you can provide callback functions via the MaskRequestBody and MaskResponseBody options. Each function receives the ended request ReadOnlySpan and the captured body as []byte. Request metadata is available through span.Attributes(). Each function should return the masked body as []byte, or nil to mask the entire body.
Callback function examples
Callbacks are applied before pattern-based field masking. If the returned body contains JSON, it is still masked using the default and custom MaskBodyFields patterns.

Log record masking callback

To mask sensitive data in application logs, provide a callback function via the MaskLogRecord option. The function receives a pointer to a LogRecord with the Time, Level, Message, and Attrs of the log record. You can modify the log message through record.Message and structured fields through record.Attrs. Return true to keep the record, or false to drop it.
Callback function example