jaegertracing/jaeger · error

could not convert sampling strategy type

Error message

could not convert sampling strategy type

What it means

convertStrategyTypeFromDomain returns this error when the domain sampling strategy type is neither PROBABILISTIC nor RATE_LIMITING, i.e. an unknown/unsupported enum value for the legacy Thrift representation.

Source

Thrown at internal/converter/thrift/jaeger/sampling_from_domain.go:89

func convertOperationFromDomain(s *api_v2.OperationSamplingStrategy) *sampling.OperationSamplingStrategy {
	if s == nil {
		return nil
	}
	return &sampling.OperationSamplingStrategy{
		Operation:             s.GetOperation(),
		ProbabilisticSampling: convertProbabilisticFromDomain(s.GetProbabilisticSampling()),
	}
}

func convertStrategyTypeFromDomain(s api_v2.SamplingStrategyType) (sampling.SamplingStrategyType, error) {
	switch s {
	case api_v2.SamplingStrategyType_PROBABILISTIC:
		return sampling.SamplingStrategyType_PROBABILISTIC, nil
	case api_v2.SamplingStrategyType_RATE_LIMITING:
		return sampling.SamplingStrategyType_RATE_LIMITING, nil
	default:
		return sampling.SamplingStrategyType_PROBABILISTIC, errors.New("could not convert sampling strategy type")
	}
}

View on GitHub (pinned to 806f444784)

Solutions

  1. Set the strategy type explicitly to PROBABILISTIC or RATE_LIMITING before conversion
  2. Regenerate/upgrade the api_v2 and thrift bindings together so enum sets match
  3. Treat the error as a protocol-compat signal: log and fall back to a default strategy in the caller

Example fix

// before
resp := &api_v2.SamplingStrategyResponse{} // StrategyType unset
// after
resp := &api_v2.SamplingStrategyResponse{
  StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC,
}
Defensive patterns

Strategy: type-guard

Validate before calling

switch s.StrategyType {
case api_v2.SamplingStrategyType_PROBABILISTIC, api_v2.SamplingStrategyType_RATE_LIMITING:
    // ok
default:
    return errors.New("unsupported sampling strategy type")
}
resp, err := jaegerconv.ConvertSamplingResponseFromDomain(s)

Type guard

func convertibleStrategyType(t api_v2.SamplingStrategyType) bool {
    return t == api_v2.SamplingStrategyType_PROBABILISTIC ||
        t == api_v2.SamplingStrategyType_RATE_LIMITING
}

Try / catch

resp, err := ConvertSamplingResponseFromDomain(s)
if err != nil {
    if strings.Contains(err.Error(), "could not convert sampling strategy type") {
        return defaultSamplingResponse(), nil
    }
    return nil, err
}

Prevention

When it happens

Trigger: ConvertSamplingResponseFromDomain receives an api_v2.SamplingStrategyType outside the two known values (e.g. an enum value from a newer IDL or a zero/unset type in a hand-built struct); the switch default errors.

Common situations: Deserializing a sampling response produced by a newer service using an added enum value; constructing the strategy struct manually and leaving StrategyType unset (0 fallback in proto2 enums); IDL version skew between client and server.

Related errors


AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01). Data as JSON: /api/errors/28a791892800b818. Report an issue: GitHub.