diff --git a/extensions/diagnostics-otel/src/service-attributes.ts b/extensions/diagnostics-otel/src/service-attributes.ts index a12cee4255e9..e07038173c3a 100644 --- a/extensions/diagnostics-otel/src/service-attributes.ts +++ b/extensions/diagnostics-otel/src/service-attributes.ts @@ -109,9 +109,11 @@ export function assignOtelLogAttribute( } } -export function assignOtelLogEventAttributes( +function assignOtelEventAttributes( attributes: Record, eventAttributes: Record | undefined, + keyPrefix: string, + normalizeString?: (value: string) => string, ): void { if (!eventAttributes) { return; @@ -121,46 +123,36 @@ export function assignOtelLogEventAttributes( break; } const key = rawKey.trim(); - if (BLOCKED_OTEL_LOG_ATTRIBUTE_KEYS.has(key)) { + if ( + BLOCKED_OTEL_LOG_ATTRIBUTE_KEYS.has(key) || + redactSensitiveText(key) !== key || + !OTEL_LOG_RAW_ATTRIBUTE_KEY_RE.test(key) + ) { continue; } - if (redactSensitiveText(key) !== key) { - continue; - } - if (!OTEL_LOG_RAW_ATTRIBUTE_KEY_RE.test(key)) { - continue; - } - assignOtelLogAttribute(attributes, `openclaw.${key}`, value); + const normalized = + typeof value === "string" && normalizeString ? normalizeString(value) : value; + assignOtelLogAttribute(attributes, `${keyPrefix}${key}`, normalized); } } +export function assignOtelLogEventAttributes( + attributes: Record, + eventAttributes: Record | undefined, +): void { + assignOtelEventAttributes(attributes, eventAttributes, "openclaw."); +} + function assignOtelSecurityEventAttributes( attributes: Record, eventAttributes: Record | undefined, ): void { - if (!eventAttributes) { - return; - } - for (const [rawKey, value] of Object.entries(eventAttributes)) { - if (Object.keys(attributes).length >= MAX_OTEL_LOG_ATTRIBUTE_COUNT) { - break; - } - const key = rawKey.trim(); - if (BLOCKED_OTEL_LOG_ATTRIBUTE_KEYS.has(key)) { - continue; - } - if (redactSensitiveText(key) !== key) { - continue; - } - if (!OTEL_LOG_RAW_ATTRIBUTE_KEY_RE.test(key)) { - continue; - } - assignOtelLogAttribute( - attributes, - `openclaw.security.attribute.${key}`, - typeof value === "string" ? normalizeDiagnosticValue(value) : value, - ); - } + assignOtelEventAttributes( + attributes, + eventAttributes, + "openclaw.security.attribute.", + normalizeDiagnosticValue, + ); } export function securitySeverityText(