Default masking
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.
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 themaskQueryParams, maskHeaders, and maskBodyFields options. Patterns match anywhere within the name. Use ^ and $ anchors for exact matches, and the i flag for case-insensitive matching.
Body field patterns recursively match keys in JSON objects and replace the corresponding values only when they are strings.
The following example uses Hono. The same masking options are available for all supported frameworks.
Hono example
Body masking callbacks
For more control over body masking, you can provide callback functions via themaskRequestBody and maskResponseBody options. Each function receives the captured body as a Buffer and the ended request ReadableSpan. Request metadata is available through span.attributes. Each function should return the masked body as a Buffer, or null 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 themaskLogRecord option. The function receives an OpenTelemetry ReadWriteLogRecord. You can modify the log message with record.setBody() and structured fields with record.setAttribute(). Return the same record to keep it, or null or undefined to drop it.
Callback function example