{"record":{"id":"1e991645c95678cd","repo":"JuliusBrussee/caveman","slug":"mapped-trace-id-is-empty","errorCode":null,"errorMessage":"mapped trace_id is empty","messagePattern":"mapped trace_id is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/importers/generic.go","lineNumber":159,"sourceCode":"\t\tcase \"string\":\n\t\t\tassignString(&sp, target, asString(val))\n\t\tcase \"int\":\n\t\t\tassignInt(&sp, target, parseFlexInt(val))\n\t\tcase \"float\":\n\t\t\tsp.TotalCostUSD = roundUSD(parseFlexFloat(val))\n\t\tcase \"time\":\n\t\t\ts, ns := parseTimeFlexible(val)\n\t\t\tif target == \"timestamp\" {\n\t\t\t\tsp.Timestamp = s\n\t\t\t\tstartNs = ns\n\t\t\t} else {\n\t\t\t\tsp.EndTimestamp = s\n\t\t\t\tendNs = ns\n\t\t\t}\n\t\t}\n\t}\n\tif strings.TrimSpace(sp.TraceID) == \"\" {\n\t\treturn Span{}, nil, fmt.Errorf(\"mapped trace_id is empty\")\n\t}\n\tif strings.TrimSpace(sp.SpanID) == \"\" {\n\t\treturn Span{}, nil, fmt.Errorf(\"mapped span_id is empty\")\n\t}\n\tif sp.Timestamp == \"\" {\n\t\treturn Span{}, nil, fmt.Errorf(\"mapped timestamp is missing or invalid\")\n\t}\n\tif d := durationMS(startNs, endNs); d > 0 {\n\t\tsp.DurationMS = d\n\t}\n\tsp.Attributes = map[string]string{\"import.source\": \"generic\"}\n\tapplyScope(&sp, opts)\n\treturn sp, resolved, nil\n}\n\nfunc assignString(sp *Span, target, v string) {\n\tswitch target {\n\tcase \"trace_id\":","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/importers/generic.go#L141-L177","documentation":"After mapping, the generic importer checks that the resolved trace_id is non-empty (after trimming whitespace). This error means the mapped path resolved to a value, but the resulting string is empty or whitespace — the record effectively has no trace identity. It is fail-closed so blank-key spans are never ingested.","triggerScenarios":"A record contains the mapped trace_id key but with value \"\", \"   \", or null, so lookupPath succeeds but asString yields an empty string.","commonSituations":"Upstream export wrote empty trace IDs for orphaned spans; a CSV-to-JSON converter emitted \"\" instead of omitting the field; JSON null at the mapped path; data migration left placeholder blanks.","solutions":["Inspect records for empty/null values at the mapped trace_id path and remove or repair them","Filter out records with blank trace IDs before calling Parse","Fix the upstream exporter so trace IDs are always populated","If trace_id lives under a different key for empty cases, remap FieldMap to the correct path"],"exampleFix":"// before: record with null trace id\n{\"trace\":{\"id\":null},\"id\":\"span-1\",...}\n// after: filter before import or repair the value\n{\"trace\":{\"id\":\"abc123\"},\"id\":\"span-1\",...}","handlingStrategy":"validation","validationCode":"func hasNonEmptyString(rec map[string]any, path string) bool {\n  v, ok := lookupPath(rec, path)\n  if !ok { return false }\n  s, ok := v.(string)\n  return ok && strings.TrimSpace(s) != \"\"\n}\n// guard: if !hasNonEmptyString(rec, fieldMap[\"trace_id\"]) { skip/log record }","typeGuard":"func nonEmptyString(v any) bool { s, ok := v.(string); return ok && strings.TrimSpace(s) != \"\" }","tryCatchPattern":"rows, err := importers.Parse(data, opts)\nif err != nil {\n  if strings.Contains(err.Error(), \"mapped trace_id is empty\") {\n    return fmt.Errorf(\"drop/repair records with blank trace_id before import: %w\", err)\n  }\n  return err\n}","preventionTips":["Filter blank/null trace IDs out before calling Parse","Audit upstream exports for empty identity fields","Treat null and \"\" at mapped paths as missing during pre-validation","Repair orphaned spans at the exporter rather than the importer"],"tags":["import","field-mapping","validation"],"backgroundTag":"empty-required-field","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}