{"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/27d5a3981a347890211bb1bf2439e5c821a63bc9/shared/platform/importers/generic.go#L141-L177","documentation":"After mapping, mapGeneric verifies the resolved TraceID is non-empty after TrimSpace. This triggers when the source path WAS found but its value was empty, whitespace, or converted to an empty string by asString. It is distinct from error 1182 (path not found): here the path resolved but produced no usable identifier.","triggerScenarios":"Records where the trace-id field exists but is \"\" or \"   \"; a null JSON value that asString renders as empty; a numeric 0 or false in the trace-id field being stringified into something empty; mapping trace_id to a path that resolves to an object/array.","commonSituations":"Vendor exports that emit empty trace IDs for rootless/system spans; records from a pre-migration system that did not set trace IDs; mapping trace_id to the wrong field that is usually populated but empty on summary rows.","solutions":["Find the offending record (it is the one at the failing position) and either populate a real trace ID upstream or drop it","If the field is sometimes empty, pre-process the data to synthesize a deterministic trace ID before import","Double-check the mapping does not point at a sibling field that is frequently empty","Treat empty trace/span IDs as data-quality defects at the source system, not importer configuration"],"exampleFix":"// before\nrec := map[string]any{\"traceId\": \"\", \"spanId\": \"s1\", \"started_at\": \"2026-01-01T00:00:00Z\"}\n\n// after\nrec := map[string]any{\"traceId\": \"gen-trace-1\", \"spanId\": \"s1\", \"started_at\": \"2026-01-01T00:00:00Z\"}","handlingStrategy":"validation","validationCode":"func hasNonEmptyTraceID(rec map[string]any, path string) bool {\n\tv, ok := lookupPath(rec, path)\n\tif !ok { return false }\n\ts, ok := v.(string)\n\treturn ok && strings.TrimSpace(s) != \"\"\n}","typeGuard":"func isUsableID(v any) bool {\n\ts, ok := v.(string)\n\treturn ok && strings.TrimSpace(s) != \"\"\n}","tryCatchPattern":"if strings.Contains(err.Error(), \"trace_id is empty\") { /* identify and drop/synthesize IDs for offending records */ }","preventionTips":["Pre-scan records and synthesize deterministic trace IDs where empty (e.g. hash of record)","Treat empty identifiers as export defects; alert on them in the source pipeline","Never map trace_id to a field that is optional in the source schema"],"tags":["go","import","generic","data-quality"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}