AiDataSanitizer
class AiDataSanitizer
| internal |
Constants
| MAX_MESSAGE_BYTES |
Maximum total byte size for serialized message data. |
| MAX_SINGLE_MESSAGE_CONTENT_BYTES |
Maximum byte length for a single message's content string. |
| JSON_FLAGS |
Preserve readable text while replacing invalid UTF-8 in telemetry. |
| BLOB_SUBSTITUTE |
Placeholder for binary content that should not be sent to Sentry. |
| private DATA_URI_PATTERN |
Regex pattern to detect data URIs (e.g. data:image/png;base64,...). |
| private BASE64_PATTERN |
Regex pattern to detect standalone base64-encoded strings (100+ chars). |
Methods
Limit a string to the configured byte budget.
Limit the byte length of one message's content without splitting a UTF-8 character.
Replace encoded binary content with a placeholder.
Encode arbitrary values using json_encode unless they are strings already, in which
case the same string is returned.
Encode a structured field within its byte budget, without cutting JSON.
Details
at line 33
static string|null
truncateString(string|null $value, int $maxBytes = self::MAX_MESSAGE_BYTES)
Limit a string to the configured byte budget.
at line 49
static string
truncateContentString(string $value)
Limit the byte length of one message's content without splitting a UTF-8 character.
at line 61
static string
redactBinaryInString(string $value)
Replace encoded binary content with a placeholder.
at line 76
static string|null
encodeIfNotString(mixed $data = null)
Encode arbitrary values using json_encode unless they are strings already, in which
case the same string is returned.
If encoding fails or exceeds the byte budget, return null. We don't distinguish a lot here between null and false, both mean that we do not want to include them as facts.
at line 90
static string|null
encode(mixed $data, int $maxBytes = self::MAX_MESSAGE_BYTES)
Encode a structured field within its byte budget, without cutting JSON.