{"record":{"id":"4ef233c0a99c40da","repo":"jaegertracing/jaeger","slug":"invalid-traceid-length-d","errorCode":null,"errorMessage":"invalid TraceID length: %d","messagePattern":"invalid TraceID length: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/v1/cassandra/spanstore/dbmodel/ids.go","lineNumber":45,"sourceCode":"func (t TraceID) MarshalJSON() ([]byte, error) {\n\tvar out [26]byte\n\tout[0] = '\"'\n\tbase64.StdEncoding.Encode(out[1:25], t[:])\n\tout[25] = '\"'\n\treturn out[:], nil\n}\n\nfunc (t *TraceID) UnmarshalJSON(data []byte) error {\n\tvar s string\n\tif err := json.Unmarshal(data, &s); err != nil {\n\t\treturn err\n\t}\n\tb, err := base64.StdEncoding.DecodeString(s)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(b) != 16 {\n\t\treturn fmt.Errorf(\"invalid TraceID length: %d\", len(b))\n\t}\n\tcopy(t[:], b)\n\treturn nil\n}\n","sourceCodeStart":27,"sourceCodeEnd":50,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/internal/storage/v1/cassandra/spanstore/dbmodel/ids.go#L27-L50","documentation":"TraceID.UnmarshalJSON decodes a base64-encoded trace ID string from JSON and requires the decoded bytes to be exactly 16 bytes (128 bits), the fixed Cassandra storage width. If the JSON field holds a base64 string that decodes to any other length, the unmarshal fails with this error rather than silently producing a zero-padded or truncated trace ID.","triggerScenarios":"Unmarshalling JSON (via encoding/json or gocql) into dbmodel.TraceID where the string field is not base64 of exactly 16 bytes — e.g. a hex string like \"00000000000000000000000000000001\" without base64 encoding, an empty string, or a 8-byte/24-byte value.","commonSituations":"Importing traces from another storage backend that serializes trace IDs as hex or as 8-byte IDs (Zipkin-style 64-bit IDs); hand-crafted JSON fixtures in tests; a migration tool writing the wrong encoding.","solutions":["Base64-encode the 16-byte trace ID (std encoding) before writing it into JSON.","If the source IDs are hex, convert hex string to 16 raw bytes and then base64-encode, e.g. hex.DecodeString then base64.StdEncoding.EncodeToString.","For 64-bit legacy IDs, left-pad to 16 bytes before encoding, matching Jaeger's zero-padded 128-bit representation.","Check the producing system's serialization format and align it with dbmodel.TraceID's expected base64-of-16-bytes form."],"exampleFix":"// before\njson := `{\"trace_id\":\"00000000000000000000000000000001\"}` // hex, decodes to 22 raw bytes\n// after\nb := make([]byte, 16)\nbinary.BigEndian.PutUint64(b[8:], 1)\njson := fmt.Sprintf(`{\"trace_id\":\"%s\"}`, base64.StdEncoding.EncodeToString(b))","handlingStrategy":"validation","validationCode":"b, err := base64.StdEncoding.DecodeString(idStr)\nif err != nil || len(b) != 16 {\n    return fmt.Errorf(\"trace ID must be base64 of exactly 16 bytes, got %d bytes\", len(b))\n}","typeGuard":"func isValidTraceID(s string) bool {\n    b, err := base64.StdEncoding.DecodeString(s)\n    return err == nil && len(b) == 16\n}","tryCatchPattern":"var id dbmodel.TraceID\nif err := json.Unmarshal(data, &id); err != nil {\n    // handle invalid-length/encoding trace ID before use\n    return fmt.Errorf(\"bad trace id in payload: %w\", err)\n}","preventionTips":["Always serialize trace IDs as base64 of the raw 16 bytes.","Convert hex-encoded IDs to 16 bytes before encoding for Jaeger's storage model.","Add a round-trip test (marshal then unmarshal) for trace ID fixtures.","Zero-pad 64-bit legacy IDs to 128 bits."],"tags":["cassandra","json","serialization","trace-id"],"backgroundTag":"invalid-identifier-length","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}