JuliusBrussee/caveman · error
mapped span_id is empty
Error message
mapped span_id is empty
What it means
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.
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
Example fix
// before
{"trace":{"id":"abc"},"id":"",...}
// after
{"trace":{"id":"abc"},"id":"span-1",...} Defensive patterns
Strategy: validation
Validate before calling
func hasSpanID(rec map[string]any, path string) bool {
v, ok := lookupPath(rec, path); if !ok { return false }
s, ok := v.(string); return ok && strings.TrimSpace(s) != ""
}
// guard: if !hasSpanID(rec, fieldMap["span_id"]) { skip record } Type guard
func nonEmptyString(v any) bool { s, ok := v.(string); return ok && strings.TrimSpace(s) != "" } Try / catch
rows, err := importers.Parse(data, opts)
if err != nil {
if strings.Contains(err.Error(), "mapped span_id is empty") {
return fmt.Errorf("records with blank span_id must be repaired or skipped: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: A record contains the mapped span_id key with value "", whitespace, or null, so the path resolves but the mapped string is empty.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- mapped source path for required target was not found
- mapped trace_id is empty
- generic decode: expected a JSON array or
- mapped timestamp is missing or invalid
- apiKey, baseURL, and agent are required
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/4315e8062f2240b8.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/importers/generic.go:162
assignInt(&sp, target, parseFlexInt(val))
case "float":
sp.TotalCostUSD = roundUSD(parseFlexFloat(val))
case "time":
s, ns := parseTimeFlexible(val)
if target == "timestamp" {
sp.Timestamp = s
startNs = ns
} else {
sp.EndTimestamp = s
endNs = ns
}
}
}
if strings.TrimSpace(sp.TraceID) == "" {
return Span{}, nil, fmt.Errorf("mapped trace_id is empty")
}
if strings.TrimSpace(sp.SpanID) == "" {
return Span{}, nil, fmt.Errorf("mapped span_id is empty")
}
if sp.Timestamp == "" {
return Span{}, nil, fmt.Errorf("mapped timestamp is missing or invalid")
}
if d := durationMS(startNs, endNs); d > 0 {
sp.DurationMS = d
}
sp.Attributes = map[string]string{"import.source": "generic"}
applyScope(&sp, opts)
return sp, resolved, nil
}
func assignString(sp *Span, target, v string) {
switch target {
case "trace_id":
sp.TraceID = v
case "span_id":
sp.SpanID = vView on GitHub (pinned to 3ee70a1026)