{"record":{"id":"4315e8062f2240b8","repo":"JuliusBrussee/caveman","slug":"mapped-span-id-is-empty","errorCode":null,"errorMessage":"mapped span_id is empty","messagePattern":"mapped span_id is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/importers/generic.go","lineNumber":162,"sourceCode":"\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\":\n\t\tsp.TraceID = v\n\tcase \"span_id\":\n\t\tsp.SpanID = v","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/importers/generic.go#L144-L180","documentation":"Same guard as trace_id but for span_id: after mapping, the resolved span_id must be a non-empty, non-whitespace string. The importer rejects records where the mapped path resolves but yields an empty value, since a span without a span ID cannot be uniquely identified.","triggerScenarios":"A record contains the mapped span_id key with value \"\", whitespace, or null, so the path resolves but the mapped string is empty.","commonSituations":"Exporter emitted blank span IDs for root-less events; null values from JSON serializers; schema drift where the ID moved to another key but the old empty key still exists.","solutions":["Check records for empty/null span_id values at the mapped path and repair or drop them","Remap FieldMap.span_id to the path that actually holds the ID","Filter records lacking a span ID before calling Parse","Fix the upstream exporter to always emit a span ID"],"exampleFix":"// before\n{\"trace\":{\"id\":\"abc\"},\"id\":\"\",...}\n// after\n{\"trace\":{\"id\":\"abc\"},\"id\":\"span-1\",...}","handlingStrategy":"validation","validationCode":"func hasSpanID(rec map[string]any, path string) bool {\n  v, ok := lookupPath(rec, path); if !ok { return false }\n  s, ok := v.(string); return ok && strings.TrimSpace(s) != \"\"\n}\n// guard: if !hasSpanID(rec, fieldMap[\"span_id\"]) { skip 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 span_id is empty\") {\n    return fmt.Errorf(\"records with blank span_id must be repaired or skipped: %w\", err)\n  }\n  return err\n}","preventionTips":["Pre-validate span IDs are non-empty strings before import","Drop records lacking span IDs at the source","Remap FieldMap.span_id when the ID moved to a new key","Generate deterministic IDs at export time when the source omits them"],"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"}