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

  1. Check records for empty/null span_id values at the mapped path and repair or drop them
  2. Remap FieldMap.span_id to the path that actually holds the ID
  3. Filter records lacking a span ID before calling Parse
  4. 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

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


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 = v

View on GitHub (pinned to 3ee70a1026)