JuliusBrussee/caveman · error
generic import requires a
Error message
generic import requires a %q mapping
What it means
Beyond per-entry checks, the field map must include mappings for the three required caveman.spans columns: trace_id, span_id, and timestamp. One of them is missing, so valid spans cannot be constructed.
Solutions
- Add mappings for trace_id, span_id, and timestamp to the FieldMap (the error names the first missing one).
- If the input lacks these fields, synthesize them upstream (e.g. derive trace_id from a request id, timestamp from file mtime) before import.
- Run validateGenericFieldMap-equivalent checks locally before invoking Parse().
- Start from a field-map template containing the three required keys.
Example fix
// before
fieldMap := map[string]string{"service": "svc", "name": "op"} // missing required keys
// after
fieldMap := map[string]string{
"trace_id": "traceId", "span_id": "spanId", "timestamp": "ts",
"service": "svc", "name": "op",
} Defensive patterns
Strategy: validation
Validate before calling
var requiredTargets = []string{"trace_id", "span_id", "timestamp"}
for _, t := range requiredTargets {
if _, ok := opts.FieldMap[t]; !ok {
return fmt.Errorf("field map missing required target %q", t)
}
} Try / catch
rows, err := importers.ParseGeneric(data, opts)
if err != nil {
if strings.Contains(err.Error(), "mapping\"") {
return fmt.Errorf("add the required trace_id/span_id/timestamp mappings: %w", err)
}
return err
} Prevention
- Start every generic-import field map from a template containing the three required keys.
- Validate required keys in your CLI/config layer before invoking Parse().
- Synthesize missing identity/timestamp fields upstream if the source lacks them.
When it happens
Trigger: Parse() with a FieldMap lacking any of the keys "trace_id", "span_id", or "timestamp".
Common situations: Mapping only descriptive columns (service/name) and forgetting identity/timing fields; building the map incrementally in code and missing a required key; minimal template configs.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- generic import requires a non-empty field map
- generic target requires a non-empty source path
- mapped source path for target was not found in any record
- unknown target column
- generic record
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/b87aee25bea926eb.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/importers/generic.go:104
}
return rows, nil
}
func validateGenericFieldMap(fieldMap map[string]string) error {
if len(fieldMap) == 0 {
return fmt.Errorf("generic import requires a non-empty field map")
}
for target, path := range fieldMap {
if _, ok := genericTargets[target]; !ok {
return fmt.Errorf("unknown target column %q (not a caveman.spans column)", target)
}
if strings.TrimSpace(path) == "" {
return fmt.Errorf("generic target %q requires a non-empty source path", target)
}
}
for _, target := range []string{"trace_id", "span_id", "timestamp"} {
if _, ok := fieldMap[target]; !ok {
return fmt.Errorf("generic import requires a %q mapping", target)
}
}
return nil
}
func decodeGenericRecords(data []byte) ([]map[string]any, error) {
// Try a bare array first.
var arr []map[string]any
if err := json.Unmarshal(data, &arr); err == nil {
return arr, nil
}
// Then a {"data":[...]} wrapper.
var env struct {
Data []map[string]any `json:"data"`
}
if err := json.Unmarshal(data, &env); err == nil && env.Data != nil {
return env.Data, nil
}View on GitHub (pinned to 3ee70a1026)