From 79df8c49db64cd57f6e314c554083dab80e9e2e0 Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Sun, 21 Jun 2026 18:37:00 +0800 Subject: [PATCH] fix: normalize Tempo search trace ids (#589) Co-authored-by: Codex --- scripts/src/platform-infra-observability.ts | 34 ++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/scripts/src/platform-infra-observability.ts b/scripts/src/platform-infra-observability.ts index d1681766..7c6d2e75 100644 --- a/scripts/src/platform-infra-observability.ts +++ b/scripts/src/platform-infra-observability.ts @@ -1796,10 +1796,23 @@ def trace_id_from_meta(meta): return None for key in ("traceID", "traceId", "trace_id"): value = meta.get(key) - if isinstance(value, str) and value: - return value + normalized = normalize_trace_id(value) + if normalized is not None: + return normalized return None +def normalize_trace_id(value): + if not isinstance(value, str): + return None + text = value.strip().lower() + if text.startswith("0x"): + text = text[2:] + if not text or len(text) > 32: + return None + if any(ch not in "0123456789abcdef" for ch in text): + return None + return text.rjust(32, "0") + def compact_meta(meta): if not isinstance(meta, dict): return {} @@ -2133,10 +2146,23 @@ def trace_id_from_meta(meta): return None for key in ("traceID", "traceId", "trace_id"): value = meta.get(key) - if isinstance(value, str) and value: - return value + normalized = normalize_trace_id(value) + if normalized is not None: + return normalized return None +def normalize_trace_id(value): + if not isinstance(value, str): + return None + text = value.strip().lower() + if text.startswith("0x"): + text = text[2:] + if not text or len(text) > 32: + return None + if any(ch not in "0123456789abcdef" for ch in text): + return None + return text.rjust(32, "0") + def compact_meta(meta): if not isinstance(meta, dict): return {}