{"record":{"id":"d9d81fc1d6275f7f","repo":"jaegertracing/jaeger","slug":"failed-to-marshal-map-attribute-q-w","errorCode":null,"errorMessage":"failed to marshal map attribute %q: %w","messagePattern":"failed to marshal map attribute %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/v2/clickhouse/tracestore/query_builder.go","lineNumber":253,"sourceCode":"\treturn append(args, key, value, key, value, key, value, key, value, key, value)\n}\n\nfunc buildBytesAttributeCondition(q *strings.Builder, args []any, key string, attr pcommon.Value) []any {\n\treturn buildSimpleAttributeCondition(q, args, \"@bytes@\"+key, pcommon.ValueTypeBytes, base64.StdEncoding.EncodeToString(attr.Bytes().AsRaw()))\n}\n\nfunc buildSliceAttributeCondition(q *strings.Builder, args []any, key string, attr pcommon.Value) ([]any, error) {\n\tb, err := marshalValueForQuery(attr)\n\tif err != nil {\n\t\treturn args, fmt.Errorf(\"failed to marshal slice attribute %q: %w\", key, err)\n\t}\n\treturn buildSimpleAttributeCondition(q, args, \"@slice@\"+key, pcommon.ValueTypeSlice, b), nil\n}\n\nfunc buildMapAttributeCondition(q *strings.Builder, args []any, key string, attr pcommon.Value) ([]any, error) {\n\tb, err := marshalValueForQuery(attr)\n\tif err != nil {\n\t\treturn args, fmt.Errorf(\"failed to marshal map attribute %q: %w\", key, err)\n\t}\n\treturn buildSimpleAttributeCondition(q, args, \"@map@\"+key, pcommon.ValueTypeMap, b), nil\n}\n\nfunc parseStringToTypedValue(key string, attr pcommon.Value, t pcommon.ValueType) (typedAttributeValue, error) {\n\tswitch t {\n\tcase pcommon.ValueTypeBool:\n\t\tb, parseErr := strconv.ParseBool(attr.Str())\n\t\tif parseErr != nil {\n\t\t\treturn typedAttributeValue{}, fmt.Errorf(\"failed to parse bool attribute %q: %w\", key, parseErr)\n\t\t}\n\t\treturn typedAttributeValue{key: key, value: b, valueType: t}, nil\n\tcase pcommon.ValueTypeDouble:\n\t\tf, parseErr := strconv.ParseFloat(attr.Str(), 64)\n\t\tif parseErr != nil {\n\t\t\treturn typedAttributeValue{}, fmt.Errorf(\"failed to parse double attribute %q: %w\", key, parseErr)\n\t\t}\n\t\treturn typedAttributeValue{key: key, value: f, valueType: t}, nil","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/internal/storage/v2/clickhouse/tracestore/query_builder.go#L235-L271","documentation":"buildMapAttributeCondition serializes a map-typed attribute via marshalValueForQuery before building the @map@ condition. A marshal failure is wrapped with this message, naming the attribute key, and aborts query construction.","triggerScenarios":"A FindTraceIDs query includes a map attribute whose values cannot be marshaled — e.g. a map containing nested unsupported value types or a corrupt pcommon.Value map.","commonSituations":"Passing OTLP-derived map attributes (e.g. http.request.headers) with nested containers into the search API; programmatic construction of malformed map values.","solutions":["Check the wrapped error to identify which map value failed to serialize","Flatten nested map values into string/int entries before querying","Pre-marshal map attributes in the caller to catch issues early","Restrict query attributes to maps of scalar values"],"exampleFix":"// before: nested map value\nm.PutVal(\"nested\", pcommon.NewValueEmpty().SetEmptyMapVal())\n// after: scalar values only\nm.PutStr(\"nested\", flattenedJSON)","handlingStrategy":"validation","validationCode":"for _, k := range attr.Map().Keys() {\n    v := attr.MapVal()\n    val, _ := v.Get(k)\n    t := val.Type()\n    if t == pcommon.ValueTypeMap || t == pcommon.ValueTypeSlice {\n        return fmt.Errorf(\"map attribute %q has non-scalar value %q\", key, k)\n    }\n}","typeGuard":"func isScalarOnlyMap(v pcommon.Value) bool {\n    if v.Type() != pcommon.ValueTypeMap { return false }\n    ok := true\n    v.Map().Range(func(_ string, val pcommon.Value) bool {\n        if val.Type() == pcommon.ValueTypeMap || val.Type() == pcommon.ValueTypeSlice {\n            ok = false\n        }\n        return ok\n    })\n    return ok\n}","tryCatchPattern":"traceIDs, err := store.FindTraceIDs(ctx, query)\nif err != nil && strings.Contains(err.Error(), \"failed to marshal map attribute\") {\n    log.Warn(\"unserializable map attribute in query\", \"err\", err)\n    return err\n}","preventionTips":["Restrict map search attributes to scalar values","Flatten nested OTLP maps into dotted-key scalars before querying","Add marshal pre-checks in the query construction layer"],"tags":["clickhouse","serialization","attributes","query-builder"],"backgroundTag":"attribute-serialization-failed","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}