go-redis/redis · error

failed to create connection count metric: %w

Error message

failed to create connection count metric: %w

What it means

Returned by createRecorder (redisotel.go:211) when meter.Int64UpDownCounter fails to create the 'db.client.connection.count' instrument. Only checked when MetricGroupConnectionBasic is enabled. The wrapped error comes from the OTel SDK.

Source

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

		if err != nil {
			return nil, fmt.Errorf("failed to create operation duration histogram: %w", err)
		}
		operationDuration = operationDurationConv.Inst()
	}

	var connectionCount metric.Int64UpDownCounter // OTel semconv: UpDownCounter
	var connectionCreateTime metric.Float64Histogram
	var connectionRelaxedTimeout metric.Int64UpDownCounter
	var connectionHandoff metric.Int64Counter

	if cfg.isMetricGroupEnabled(MetricGroupConnectionBasic) {
		connectionCount, err = meter.Int64UpDownCounter(
			dbconv.ClientConnectionCount{}.Name(),
			metric.WithDescription(dbconv.ClientConnectionCount{}.Description()),
			metric.WithUnit(dbconv.ClientConnectionCount{}.Unit()),
		)
		if err != nil {
			return nil, fmt.Errorf("failed to create connection count metric: %w", err)
		}

		var connectionCreateTimeOpts []metric.Float64HistogramOption
		if cfg.histAggregation == HistogramAggregationExplicitBucket {
			connectionCreateTimeOpts = append(connectionCreateTimeOpts,
				metric.WithExplicitBucketBoundaries(cfg.bucketsConnectionCreateTime...),
			)
		}
		var connectionCreateTimeConv dbconv.ClientConnectionCreateTime
		connectionCreateTimeConv, err = dbconv.NewClientConnectionCreateTime(meter, connectionCreateTimeOpts...)
		if err != nil {
			return nil, fmt.Errorf("failed to create connection create time histogram: %w", err)
		}
		connectionCreateTime = connectionCreateTimeConv.Inst()

		connectionRelaxedTimeout, err = meter.Int64UpDownCounter(
			MetricConnectionRelaxedTimeout,
			metric.WithDescription("How many times the connection timeout has been increased/decreased (after a server maintenance notification)"),

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Find and reconcile any other registration of 'db.client.connection.count' so the instrument type and metadata match
  2. Ensure only one redisotel-native Init runs per process (the initialized guard prevents this, but other OTel integrations may conflict)
  3. Verify the MeterProvider and SDK version are compatible

Example fix

// before - another lib registers the same name as a Counter
meter.Int64Counter("db.client.connection.count") // type mismatch

// after - use UpDownCounter to match redisotel semconv
meter.Int64UpDownCounter("db.client.connection.count")
Defensive patterns

Strategy: try-catch

Try / catch

if err := obs.Init(cfg); err != nil {
    if strings.Contains(err.Error(), "connection count metric") {
        log.Error("conflict on 'db.client.connection.count'; another lib registered it with conflicting type/metadata")
    }
}

Prevention

When it happens

Trigger: Calling Init with MetricGroupFlagConnectionBasic enabled, and the OTel SDK rejects the UpDownCounter creation.

Common situations: Another instrumentation library or a second redisotel Init call registered 'db.client.connection.count' with a conflicting instrument type (e.g., Counter instead of UpDownCounter) or different metadata; incompatible OTel SDK.

Related errors


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/910b30046caa94f4.json. Report an issue: GitHub.