fix: normalize Tempo search trace ids (#589)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
@@ -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 {}
|
||||
|
||||
Reference in New Issue
Block a user