refactor(diagnostics-otel): unify event attribute projection (#122559)

This commit is contained in:
Vincent Koc
2026-08-12 18:06:08 +08:00
committed by GitHub
parent 9324843d42
commit fb788e7a3e
@@ -109,9 +109,11 @@ export function assignOtelLogAttribute(
}
}
export function assignOtelLogEventAttributes(
function assignOtelEventAttributes(
attributes: Record<string, string | number | boolean>,
eventAttributes: Record<string, string | number | boolean> | 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<string, string | number | boolean>,
eventAttributes: Record<string, string | number | boolean> | undefined,
): void {
assignOtelEventAttributes(attributes, eventAttributes, "openclaw.");
}
function assignOtelSecurityEventAttributes(
attributes: Record<string, string | number | boolean>,
eventAttributes: Record<string, string | number | boolean> | 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(