in src/OpenTelemetry.php [102:122]
private static function sanitizeBody(string $body, array $sanitizeKeys): string
{
if (empty($body)) {
return '';
}
$json = json_decode($body, true);
if (!is_array($json)) {
return '';
}
$patterns = array_merge(self::DEFAULT_SANITIZER_KEY_PATTERNS, $sanitizeKeys);
// Convert the patterns array into a regex
$regex = sprintf('/%s/', implode('|', $patterns));
// Recursively traverse the array and redact the specified keys
array_walk_recursive($json, function (&$value, $key) use ($regex) {
if (preg_match($regex, $key, $matches)) {
$value = self::REDACTED_STRING;
}
});
return JsonSerializer::serialize($json);
}