jaegertracing/jaeger · error

could not convert sampling strategy type

Error message

could not convert sampling strategy type

What it means

convertStrategyTypeToDomain returns this error when the legacy Thrift sampling strategy type is neither PROBABILISTIC nor RATE_LIMITING, so it cannot be mapped into the domain model enum. The function returns the zero domain value alongside the error.

Source

Thrown at internal/converter/thrift/jaeger/sampling_to_domain.go:71

			ProbabilisticSampling: convertProbabilisticToDomain(pos.GetProbabilisticSampling()),
		}
	}
	return &api_v2.PerOperationSamplingStrategies{
		DefaultSamplingProbability:       s.GetDefaultSamplingProbability(),
		DefaultUpperBoundTracesPerSecond: s.GetDefaultUpperBoundTracesPerSecond(),
		DefaultLowerBoundTracesPerSecond: s.GetDefaultLowerBoundTracesPerSecond(),
		PerOperationStrategies:           poss,
	}
}

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

View on GitHub (pinned to 806f444784)

Solutions

  1. Ensure the remote client only sends PROBABILISTIC or RATE_LIMITING strategy types
  2. Align the thrift IDL/generated code versions on both sides of the conversion
  3. In the caller, check err != nil and fall back to a default sampling response instead of using the zero-value result

Example fix

// before
resp, err := ConvertSamplingResponseToDomain(thriftResp) // thriftResp.StrategyType unknown
_ = resp // zero-value result used even on error
// after
resp, err := ConvertSamplingResponseToDomain(thriftResp)
if err != nil {
  resp = defaultSamplingResponse()
}
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

func convertibleToDomain(t sampling.SamplingStrategyType) bool {
    return t == sampling.SamplingStrategyType_PROBABILISTIC ||
        t == sampling.SamplingStrategyType_RATE_LIMITING
}

Try / catch

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

Prevention

When it happens

Trigger: ConvertSamplingResponseToDomain receives a sampling.SamplingStrategyType outside the two known enum values — typically a value added by a newer Thrift IDL or a corrupt/unknown wire value; the switch default errors.

Common situations: Old/other Jaeger clients sending a strategy type this converter doesn't know; thrift IDL mismatch between the remote client library and the collector's generated code; fuzzed or malformed remote-sampling responses.

Related errors


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