{"record":{"id":"ef06b996fec55660","repo":"jaegertracing/jaeger","slug":"maxtracespersecond-is-higher-than-int16","errorCode":null,"errorMessage":"maxTracesPerSecond is higher than int16","messagePattern":"maxTracesPerSecond is higher than int16","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/converter/thrift/jaeger/sampling_from_domain.go","lineNumber":45,"sourceCode":"\t\tRateLimitingSampling:  rl,\n\t\tOperationSampling:     convertPerOperationFromDomain(r.GetOperationSampling()),\n\t}\n\treturn thriftResp, nil\n}\n\nfunc convertProbabilisticFromDomain(s *api_v2.ProbabilisticSamplingStrategy) *sampling.ProbabilisticSamplingStrategy {\n\tif s == nil {\n\t\treturn nil\n\t}\n\treturn &sampling.ProbabilisticSamplingStrategy{SamplingRate: s.GetSamplingRate()}\n}\n\nfunc convertRateLimitingFromDomain(s *api_v2.RateLimitingSamplingStrategy) (*sampling.RateLimitingSamplingStrategy, error) {\n\tif s == nil {\n\t\treturn nil, nil\n\t}\n\tif s.MaxTracesPerSecond > math.MaxInt16 {\n\t\treturn nil, errors.New(\"maxTracesPerSecond is higher than int16\")\n\t}\n\treturn &sampling.RateLimitingSamplingStrategy{\n\t\t//nolint:gosec // G115\n\t\tMaxTracesPerSecond: int16(s.GetMaxTracesPerSecond()),\n\t}, nil\n}\n\nfunc convertPerOperationFromDomain(s *api_v2.PerOperationSamplingStrategies) *sampling.PerOperationSamplingStrategies {\n\tif s == nil {\n\t\treturn nil\n\t}\n\tr := &sampling.PerOperationSamplingStrategies{\n\t\tDefaultSamplingProbability:       s.GetDefaultSamplingProbability(),\n\t\tDefaultLowerBoundTracesPerSecond: s.GetDefaultLowerBoundTracesPerSecond(),\n\t\tDefaultUpperBoundTracesPerSecond: &s.DefaultUpperBoundTracesPerSecond,\n\t}\n\n\tperOp := s.GetPerOperationStrategies()","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/internal/converter/thrift/jaeger/sampling_from_domain.go#L27-L63","documentation":"convertRateLimitingFromDomain returns this error when the domain model's MaxTracesPerSecond exceeds math.MaxInt16. The Thrift (jaeger-api_v2 to legacy thrift) representation stores the rate as int16, so larger values cannot be represented and would silently truncate.","triggerScenarios":"Calling ConvertSamplingResponseFromDomain with a RateLimitingSamplingStrategy whose MaxTracesPerSecond > 32767; convertRateLimitingFromDomain performs the explicit range check and errors instead of narrowing.","commonSituations":"Custom adaptive sampling backends producing very high rate-limit values; misconfigured rate limits entered as, e.g., 100000 traces/sec; converters used in dual-protocol collectors bridging OTLP-era domain types to legacy Thrift clients.","solutions":["Lower the sampler's MaxTracesPerSecond to <= 32767 (32767 spans/sec is far beyond typical client needs)","Return an out-of-range value from your own strategy provider so the default (e.g. 1000) is used instead","Handle the returned error upstream by falling back to a default strategy rather than crashing the sampling response"],"exampleFix":"// before\nstrategy := &api_v2.RateLimitingSamplingStrategy{MaxTracesPerSecond: 100000}\n// after\nstrategy := &api_v2.RateLimitingSamplingStrategy{MaxTracesPerSecond: 1000} // must fit int16","handlingStrategy":"validation","validationCode":"if s.MaxTracesPerSecond > math.MaxInt16 {\n    s.MaxTracesPerSecond = math.MaxInt16 // or reject before converting\n}\nresp, err := jaegerconv.ConvertSamplingResponseFromDomain(strategy)\nif err != nil {\n    // fall back to default strategy\n}","typeGuard":"func fitsInt16(v int32) bool {\n    return v >= math.MinInt16 && v <= math.MaxInt16\n}","tryCatchPattern":"resp, err := ConvertSamplingResponseFromDomain(s)\nif err != nil {\n    if strings.Contains(err.Error(), \"higher than int16\") {\n        return defaultStrategy(), nil\n    }\n    return nil, err\n}","preventionTips":["Clamp MaxTracesPerSecond at the strategy provider source","Never configure rate limits above 32767 for legacy Thrift clients","Return a safe default on conversion errors"],"tags":["go","thrift","sampling","conversion","integer-overflow"],"backgroundTag":"integer-overflow-range","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}