{"record":{"id":"b4b649f2b4871877","repo":"weaviate/weaviate","slug":"opentelemetry-sampling-rate-must-be-between-0-0-a","errorCode":null,"errorMessage":"opentelemetry: sampling rate must be between 0.0 and 1.0","messagePattern":"opentelemetry: sampling rate must be between 0\\.0 and 1\\.0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"usecases/telemetry/opentelemetry/errors.go","lineNumber":24,"sourceCode":"//\n//  Copyright © 2016 - 2026 Weaviate B.V. All rights reserved.\n//\n//  CONTACT: hello@weaviate.io\n//\n\npackage opentelemetry\n\nimport \"errors\"\n\nvar (\n\t// ErrEmptyServiceName is returned when the service name is empty\n\tErrEmptyServiceName = errors.New(\"opentelemetry: service name cannot be empty\")\n\n\t// ErrEmptyExporterEndpoint is returned when the exporter endpoint is empty\n\tErrEmptyExporterEndpoint = errors.New(\"opentelemetry: exporter endpoint cannot be empty\")\n\n\t// ErrInvalidSamplingRate is returned when the sampling rate is invalid\n\tErrInvalidSamplingRate = errors.New(\"opentelemetry: sampling rate must be between 0.0 and 1.0\")\n\n\t// ErrInvalidBatchTimeout is returned when the batch timeout is invalid\n\tErrInvalidBatchTimeout = errors.New(\"opentelemetry: batch timeout must be greater than 0\")\n\n\t// ErrInvalidBatchSize is returned when the batch size is invalid\n\tErrInvalidBatchSize = errors.New(\"opentelemetry: batch size must be greater than 0\")\n\n\t// ErrExporterNotSupported is returned when the exporter protocol is not supported\n\tErrExporterNotSupported = errors.New(\"opentelemetry: exporter protocol not supported\")\n)\n","sourceCodeStart":6,"sourceCodeEnd":35,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/usecases/telemetry/opentelemetry/errors.go#L6-L35","documentation":"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.","triggerScenarios":"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.","commonSituations":"Confusing percentage with fraction (50 vs 0.5); copying a sampling rate from tooling that uses percentages; template variables substituted with wrong units.","solutions":["Express the rate as a fraction between 0.0 and 1.0 — e.g. 0.5 for 50% sampling.","Use 1.0 to sample everything or 0.0 to sample nothing.","Add a startup IsValid() check or clamp the value in your config loader before constructing the provider."],"exampleFix":"// before\ncfg := opentelemetry.Config{ServiceName: \"weaviate\", ExporterEndpoint: \"otel:4317\", SamplingRate: 50}\n// after\ncfg := opentelemetry.Config{ServiceName: \"weaviate\", ExporterEndpoint: \"otel:4317\", SamplingRate: 0.5}","handlingStrategy":"validation","validationCode":"if cfg.SamplingRate < 0.0 || cfg.SamplingRate > 1.0 {\n\treturn fmt.Errorf(\"sampling rate %v out of range [0.0, 1.0]\", cfg.SamplingRate)\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.IsValid(); err != nil {\n\tif errors.Is(err, opentelemetry.ErrInvalidSamplingRate) {\n\t\tcfg.SamplingRate = 1.0 // safe default: sample everything\n\t}\n}","preventionTips":["Always express the rate as a fraction (0.5 for 50%), never a percentage.","Parse config numbers as float64 and clamp to [0,1] at load time.","Document the unit in your config schema/example files.","Add a unit test for percentage-style values in your config loader."],"tags":["opentelemetry","configuration","tracing"],"backgroundTag":"config-value-out-of-range","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}