jaegertracing/jaeger · error
latency_unit must be "ms" or "s", not %q
Error message
latency_unit must be "ms" or "s", not %q
What it means
Configuration.Validate() in the Prometheus config package first runs struct validation, then explicitly checks that the LatencyUnit field is either "ms" or "s" (or empty). Any other string is rejected because downstream latency histogram units must map to a known time unit. This prevents silently emitting metrics with an unrecognized unit suffix.
Source
Thrown at internal/config/promcfg/config.go:38
TokenFilePath string `mapstructure:"token_file_path"`
TokenOverrideFromContext bool `mapstructure:"token_override_from_context"`
MetricNamespace string `mapstructure:"metric_namespace"`
LatencyUnit string `mapstructure:"latency_unit"`
NormalizeCalls bool `mapstructure:"normalize_calls"`
NormalizeDuration bool `mapstructure:"normalize_duration"`
// ExtraQueryParams is used to provide extra parameters to be appended
// to the URL of queries going out to the metrics backend.
ExtraQueryParams map[string]string `mapstructure:"extra_query_parameters"`
}
func (c *Configuration) Validate() error {
if _, err := govalidator.ValidateStruct(c); err != nil {
return err
}
if u := c.LatencyUnit; u != "" && u != "ms" && u != "s" {
return fmt.Errorf(`latency_unit must be "ms" or "s", not %q`, u)
}
return nil
}
View on GitHub (pinned to 806f444784)
Solutions
- Set latency_unit to exactly "ms" or "s" in the configuration
- Leave latency_unit empty ("") to use the default
- Trim whitespace and fix casing in the config value (validation is case-sensitive)
- Call Validate() early at startup so a bad value fails fast instead of at runtime
Example fix
// before
cfg := promcfg.Configuration{LatencyUnit: "millis"}
// after
cfg := promcfg.Configuration{LatencyUnit: "ms"} Defensive patterns
Strategy: validation
Validate before calling
if cfg.LatencyUnit != "" && cfg.LatencyUnit != "ms" && cfg.LatencyUnit != "s" {
return fmt.Errorf("invalid latency_unit %q; must be \"ms\" or \"s\"", cfg.LatencyUnit)
}
if err := cfg.Validate(); err != nil { return err } Prevention
- Only ever assign "ms" or "s" to LatencyUnit; prefer constants
- Leave the field empty to accept the default
- Call Validate() at config-load time, before constructing the cluster
- Beware config layers that append whitespace or change casing
When it happens
Trigger: Calling Configuration.Validate() (directly or via NewCluster) when c.LatencyUnit is set to a non-empty string other than "ms" or "s", e.g. "ms " with whitespace, "MS", "seconds", or "msec".
Common situations: Hand-editing a YAML/flag config and typing 'millis' or 'sec' for latency_unit; copying a config from another project that uses different unit strings; environment-variable interpolation producing an unexpected value.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- no sampling strategy provider specified, expecting 'adaptive
- only one sampling strategy provider can be specified, 'adapt
- reload interval must be a positive value, or zero to disable
- CalculationInterval and AggregationBuckets must be greater t
- BucketsForCalculation cannot be less than 1
AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01).
Data as JSON: /api/errors/1a588a8db03e1e55.
Report an issue: GitHub.