weaviate/weaviate · error

opentelemetry: sampling rate must be between 0.0 and 1.0

Error message

opentelemetry: sampling rate must be between 0.0 and 1.0

What it means

ErrInvalidSamplingRate is returned by the OpenTelemetry config's IsValid() when Config.SamplingRate is outside the [0.0, 1.0] range (config.go:128). The sampling rate is a fraction of traces to keep, so values like 50 (intending 50%) or negative numbers are rejected.

Source

Thrown at usecases/telemetry/opentelemetry/errors.go:24

//
//  Copyright © 2016 - 2026 Weaviate B.V. All rights reserved.
//
//  CONTACT: hello@weaviate.io
//

package opentelemetry

import "errors"

var (
	// ErrEmptyServiceName is returned when the service name is empty
	ErrEmptyServiceName = errors.New("opentelemetry: service name cannot be empty")

	// ErrEmptyExporterEndpoint is returned when the exporter endpoint is empty
	ErrEmptyExporterEndpoint = errors.New("opentelemetry: exporter endpoint cannot be empty")

	// ErrInvalidSamplingRate is returned when the sampling rate is invalid
	ErrInvalidSamplingRate = errors.New("opentelemetry: sampling rate must be between 0.0 and 1.0")

	// ErrInvalidBatchTimeout is returned when the batch timeout is invalid
	ErrInvalidBatchTimeout = errors.New("opentelemetry: batch timeout must be greater than 0")

	// ErrInvalidBatchSize is returned when the batch size is invalid
	ErrInvalidBatchSize = errors.New("opentelemetry: batch size must be greater than 0")

	// ErrExporterNotSupported is returned when the exporter protocol is not supported
	ErrExporterNotSupported = errors.New("opentelemetry: exporter protocol not supported")
)

View on GitHub (pinned to 75aa4b6d11)

Solutions

  1. Express the rate as a fraction between 0.0 and 1.0 — e.g. 0.5 for 50% sampling.
  2. Use 1.0 to sample everything or 0.0 to sample nothing.
  3. Add a startup IsValid() check or clamp the value in your config loader before constructing the provider.

Example fix

// before
cfg := opentelemetry.Config{ServiceName: "weaviate", ExporterEndpoint: "otel:4317", SamplingRate: 50}
// after
cfg := opentelemetry.Config{ServiceName: "weaviate", ExporterEndpoint: "otel:4317", SamplingRate: 0.5}
Defensive patterns

Strategy: validation

Validate before calling

if cfg.SamplingRate < 0.0 || cfg.SamplingRate > 1.0 {
	return fmt.Errorf("sampling rate %v out of range [0.0, 1.0]", cfg.SamplingRate)
}

Try / catch

if err := cfg.IsValid(); err != nil {
	if errors.Is(err, opentelemetry.ErrInvalidSamplingRate) {
		cfg.SamplingRate = 1.0 // safe default: sample everything
	}
}

Prevention

When it happens

Trigger: Configuring a sampling rate such as 50, 1.5, or -0.1 in the OpenTelemetry settings; passing an integer percentage where a fraction is expected; unmarshalling a config file where the rate is expressed as "50%" or a string.

Common situations: Confusing percentage with fraction (50 vs 0.5); copying a sampling rate from tooling that uses percentages; template variables substituted with wrong units.

Related errors


AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04). Data as JSON: /api/errors/b4b649f2b4871877. Report an issue: GitHub.