{"record":{"id":"8a9e044aa0ac9411","repo":"jaegertracing/jaeger","slug":"trace-id-must-be-32-hex-characters-got-d","errorCode":null,"errorMessage":"trace ID must be 32 hex characters, got %d","messagePattern":"trace ID must be 32 hex characters, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/jaeger/internal/extension/jaegerquery/internal/mcptools/internal/handlers/get_span_details.go","lineNumber":275,"sourceCode":"\t\t}\n\t\treturn result\n\tcase pcommon.ValueTypeMap:\n\t\tm := v.Map()\n\t\tresult := make(map[string]any)\n\t\tfor k, v := range m.All() {\n\t\t\tresult[k] = convertAttributeValue(v)\n\t\t}\n\t\treturn result\n\tdefault:\n\t\treturn nil\n\t}\n}\n\n// parseTraceID parses a trace ID string into a pcommon.TraceID.\nfunc parseTraceID(traceIDStr string) (pcommon.TraceID, error) {\n\t// Parse hex string - TraceID is 16 bytes (32 hex characters)\n\tif len(traceIDStr) != 32 {\n\t\treturn pcommon.TraceID{}, fmt.Errorf(\"trace ID must be 32 hex characters, got %d\", len(traceIDStr))\n\t}\n\n\tvar traceID pcommon.TraceID\n\tbytes, err := hex.DecodeString(traceIDStr)\n\tif err != nil {\n\t\treturn pcommon.TraceID{}, fmt.Errorf(\"invalid hex string: %w\", err)\n\t}\n\n\tcopy(traceID[:], bytes)\n\treturn traceID, nil\n}\n\n// parseSpanID parses a span ID string into a pcommon.SpanID.\nfunc parseSpanID(spanIDStr string) (pcommon.SpanID, error) {\n\t// Parse hex string - SpanID is 8 bytes (16 hex characters)\n\tif len(spanIDStr) != 16 {\n\t\treturn pcommon.SpanID{}, fmt.Errorf(\"span ID must be 16 hex characters, got %d\", len(spanIDStr))\n\t}","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/cmd/jaeger/internal/extension/jaegerquery/internal/mcptools/internal/handlers/get_span_details.go#L257-L293","documentation":"parseTraceID is the low-level helper behind the \"invalid trace_id\" wrap: it enforces that a trace ID string is exactly 32 hex characters (16 bytes / 128 bits), the W3C Trace Context width Jaeger uses. When the length check fails it emits this message with the actual length; a subsequent hex decode failure yields a separate \"invalid hex string\" error.","triggerScenarios":"Any call path reaching parseTraceID (buildQuery for span details, or the anonymous wrapper) with a trace ID string whose len != 32 — e.g. 16-char legacy IDs, IDs with a 0x prefix or dashes altering length, or truncated IDs.","commonSituations":"W3C 8-byte trace IDs from instrumented apps stored unpadded; string manipulation that truncated or concatenated IDs; IDs obtained from OTLP JSON with different encoding.","solutions":["Ensure the string is exactly 32 characters before calling; left-pad with zeros if it is 16.","Normalize: strip 0x, dashes, whitespace, and re-check len == 32.","Keep IDs as canonical lowercase hex throughout your pipeline.","Wrap your own calls with a length check and pad rather than passing through raw user/log output."],"exampleFix":"// before\nid := traceIDString() // \"e8d3fbe4e0b6e0f2\" (16 chars)\nparseTraceID(id) // -> \"trace ID must be 32 hex characters, got 16\"\n// after\nid := fmt.Sprintf(\"%032s\", traceIDString())\nparseTraceID(id) // ok","handlingStrategy":"validation","validationCode":"func ensureTraceID(s string) (string, error) {\n\ts = strings.ToLower(strings.TrimPrefix(strings.TrimSpace(s), \"0x\"))\n\tif len(s) == 16 { s = strings.Repeat(\"0\", 16) + s }\n\tif len(s) != 32 {\n\t\treturn \"\", fmt.Errorf(\"trace ID must be 32 hex characters, got %d\", len(s))\n\t}\n\tif _, err := hex.DecodeString(s); err != nil { return \"\", err }\n\treturn s, nil\n}","typeGuard":"func is32Hex(s string) bool {\n\treturn len(s) == 32 && func() bool { _, err := hex.DecodeString(s); return err == nil }()\n}","tryCatchPattern":"id, err := ensureTraceID(raw)\nif err != nil {\n\tif strings.Contains(err.Error(), \"must be 32 hex characters\") {\n\t\traw = fmt.Sprintf(\"%032s\", strings.TrimPrefix(raw, \"0x\"))\n\t\tid, err = ensureTraceID(raw)\n\t}\n}","preventionTips":["Centralize trace ID formatting in one normalize helper that pads to 32 chars.","Keep IDs as canonical lowercase hex end-to-end.","Guard against truncation when logging or copying IDs between systems.","Distinguish length errors (this message) from hex-decode errors (\"invalid hex string\") when diagnosing."],"tags":["validation","trace-id","hex","jaeger"],"backgroundTag":"invalid-trace-id-format","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}