redis/go-redis · error

failed to create connection wait time histogram: %w

Error message

failed to create connection wait time histogram: %w

What it means

Returned by createRecorder when dbconv.NewClientConnectionWaitTime fails to create the db.client.connection.wait_time histogram (advanced connection metric group). Init aborts with 'failed to create metrics recorder', so pool wait-time metrics are never installed. Root cause is MeterProvider-level instrument creation failure.

Source

Thrown at extra/redisotel-native/redisotel.go:282

			return nil, fmt.Errorf("failed to create maintenance notifications metric: %w", err)
		}
	}

	var connectionWaitTime metric.Float64Histogram
	var connectionClosed metric.Int64Counter
	var connectionPendingReqs metric.Int64UpDownCounter // OTel semconv: UpDownCounter

	if cfg.isMetricGroupEnabled(MetricGroupConnectionAdvanced) {
		var connectionWaitTimeOpts []metric.Float64HistogramOption
		if cfg.histAggregation == HistogramAggregationExplicitBucket {
			connectionWaitTimeOpts = append(connectionWaitTimeOpts,
				metric.WithExplicitBucketBoundaries(cfg.bucketsConnectionWaitTime...),
			)
		}
		var connectionWaitTimeConv dbconv.ClientConnectionWaitTime
		connectionWaitTimeConv, err = dbconv.NewClientConnectionWaitTime(meter, connectionWaitTimeOpts...)
		if err != nil {
			return nil, fmt.Errorf("failed to create connection wait time histogram: %w", err)
		}
		connectionWaitTime = connectionWaitTimeConv.Inst()

		connectionClosed, err = meter.Int64Counter(
			MetricConnectionClosed,
			metric.WithDescription("The number of connections that have been closed"),
			metric.WithUnit("{connection}"),
		)
		if err != nil {
			return nil, fmt.Errorf("failed to create connection closed metric: %w", err)
		}

		connectionPendingReqs, err = meter.Int64UpDownCounter(
			dbconv.ClientConnectionPendingRequests{}.Name(),
			metric.WithDescription(dbconv.ClientConnectionPendingRequests{}.Description()),
			metric.WithUnit(dbconv.ClientConnectionPendingRequests{}.Unit()),
		)
		if err != nil {

View on GitHub (pinned to c5cad058c7)

Solutions

  1. Fix BucketsConnectionWaitTime so boundaries are strictly increasing positive floats
  2. Fall back to HistogramAggregationDefault if explicit buckets are not essential
  3. Ensure the MeterProvider is running before Init and not previously Shutdown
  4. Unwrap the error and check otel's global error handler for the precise rejection
  5. Upgrade/align go.opentelemetry.io/otel versions across modules

Example fix

// before
cfg.BucketsConnectionWaitTime = []float64{1, 0.5, 0.1} // decreasing
// after
cfg.BucketsConnectionWaitTime = []float64{0.0001, 0.001, 0.01, 0.1, 1, 10}
Defensive patterns

Strategy: validation

Validate before calling

func bucketsOK(b []float64) bool {
    if len(b) == 0 { return false }
    for i := 1; i < len(b); i++ { if b[i] <= b[i-1] { return false } }
    return b[0] > 0
}
if !bucketsOK(cfg.BucketsConnectionWaitTime) {
    cfg.HistogramAggregation = redisotel.HistogramAggregationDefault
}

Try / catch

err := obs.Init(cfg)
if err != nil && strings.Contains(err.Error(), "connection wait time histogram") {
    cfg.BucketsConnectionWaitTime = defaultWaitTimeBuckets
    err = obs.Init(cfg)
}

Prevention

When it happens

Trigger: Init with MetricGroupFlagConnectionAdvanced enabled, HistogramAggregationExplicitBucket set, and invalid BucketsConnectionWaitTime (empty, non-increasing, or non-positive); or a MeterProvider that is shut down / rejects the dbconv semconv instrument.

Common situations: Operators copying bucket configs from other services with malformed values; provider lifecycle bugs in tests; upgrading otel SDK so histogram validation tightened.

Related errors


AI-assisted analysis of redis/go-redis@c5cad058c7 (2026-09-01). Data as JSON: /api/errors/b3936da5f70c2331. Report an issue: GitHub.