jaegertracing/jaeger · error
invalid mapping type: %s
Error message
invalid mapping type: %s
What it means
MappingTypeFromString resolves a Jaeger index base name (e.g. "jaeger-span") to a MappingType enum used to render index templates. It returns this error when the name is not one of the four recognized Jaeger index names (span, service, dependencies, sampling). The %s is echoed verbatim so the caller can see which name was rejected.
Source
Thrown at internal/storage/elasticsearch/esclient/index_template.go:52
ServiceMapping
DependencyMapping
SamplingMapping
)
// MappingTypeFromString resolves a Jaeger index base name (e.g. "jaeger-span")
// to its MappingType.
func MappingTypeFromString(name string) (MappingType, error) {
switch name {
case config.SpanIndexName:
return SpanMapping, nil
case config.ServiceIndexName:
return ServiceMapping, nil
case config.DependencyIndexName:
return DependencyMapping, nil
case config.SamplingIndexName:
return SamplingMapping, nil
default:
return 0, fmt.Errorf("invalid mapping type: %s", name)
}
}
// file returns the embedded neutral-body file name, or "" for an unknown type.
func (m MappingType) file() string {
switch m {
case SpanMapping:
return "jaeger-span.json"
case ServiceMapping:
return "jaeger-service.json"
case DependencyMapping:
return "jaeger-dependencies.json"
case SamplingMapping:
return "jaeger-sampling.json"
default:
return ""
}
}View on GitHub (pinned to 806f444784)
Solutions
- Pass the bare Jaeger base name (e.g. "jaeger-span"), not a prefixed, dated, or rollover-numbered variant
- Compare against config.SpanIndexName/ServiceIndexName/DependencyIndexName/SamplingIndexName constants instead of hand-written strings
- If handling user input, validate against the four allowed names before calling
- If you have a MappingType already, avoid the round-trip: use the enum directly rather than converting from its string form
Example fix
// before mt, err := esclient.MappingTypeFromString(prefix + "jaeger-span") // "my-prefix-jaeger-span" // after mt, err := esclient.MappingTypeFromString(config.SpanIndexName) // "jaeger-span"
Defensive patterns
Strategy: validation
Validate before calling
var validNames = map[string]bool{
config.SpanIndexName: true, config.ServiceIndexName: true,
config.DependencyIndexName: true, config.SamplingIndexName: true,
}
if !validNames[name] {
return fmt.Errorf("unsupported index name %q", name)
}
mt, err := esclient.MappingTypeFromString(name) Type guard
func isJaegerIndexName(name string) bool {
switch name {
case config.SpanIndexName, config.ServiceIndexName,
config.DependencyIndexName, config.SamplingIndexName:
return true
}
return false
} Try / catch
mt, err := esclient.MappingTypeFromString(name)
if err != nil {
return fmt.Errorf("cannot render template for %q: %w", name, err)
} Prevention
- Strip any index prefix and date/rollover suffix before resolving the mapping type
- Use the config.*IndexName constants instead of literal strings
- Never feed physical index names (from GetJaegerIndices) into template generation
- Validate user-configured index names against the four supported bases at config load time
When it happens
Trigger: Calling MappingTypeFromString with a name other than config.SpanIndexName, ServiceIndexName, DependencyIndexName, or SamplingIndexName — e.g. a typo, an index name with a prefix or date suffix attached, or a fully-qualified index name like "jaeger-span-000001" instead of the base name.
Common situations: Passing the configured index prefix plus name ("my-prefix-jaeger-span") instead of the bare base name; passing a rollover physical index name; wiring a custom index name from user config into template generation; iterating over indices returned by GetJaegerIndices (which include dates/rollover numbers) and feeding them to template generation.
Related errors
- invalid parameters
- failed to create template: %w
- failed to check if template exists: %w
- invalid mapping type %q: please pass one of %q, %q, %q, or %
- file must begin with '['
AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01).
Data as JSON: /api/errors/f8a0ab05f068efae.
Report an issue: GitHub.