redis/go-redis · error
failed to create stream lag histogram: %w
Error message
failed to create stream lag histogram: %w
What it means
During createRecorder in the native redisotel module, the Float64Histogram used to record Redis stream lag cannot be created by the OTel meter. The error is wrapped and returned from Init. Like error 90 this is an instrumentation setup failure, not a Redis-side error.
Source
Thrown at extra/redisotel-native/redisotel.go:336
var streamLag metric.Float64Histogram
if cfg.isMetricGroupEnabled(MetricGroupStream) {
var streamLagOpts []metric.Float64HistogramOption
streamLagOpts = append(streamLagOpts,
metric.WithDescription("The lag between message creation and consumption in a stream consumer group"),
metric.WithUnit("s"),
)
if cfg.histAggregation == HistogramAggregationExplicitBucket {
streamLagOpts = append(streamLagOpts,
metric.WithExplicitBucketBoundaries(cfg.bucketsStreamProcessingDuration...),
)
}
streamLag, err = meter.Float64Histogram(
MetricStreamLag,
streamLagOpts...,
)
if err != nil {
return nil, fmt.Errorf("failed to create stream lag histogram: %w", err)
}
}
// Create recorder
recorder := &metricsRecorder{
operationDuration: operationDuration,
connectionCount: connectionCount,
connectionCreateTime: connectionCreateTime,
connectionRelaxedTimeout: connectionRelaxedTimeout,
connectionHandoff: connectionHandoff,
clientErrors: clientErrors,
maintenanceNotifications: maintenanceNotifications,
connectionWaitTime: connectionWaitTime,
connectionClosed: connectionClosed,
connectionPendingReqs: connectionPendingReqs,
pubsubMessages: pubsubMessages,
streamLag: streamLag,
cfg: &cfg,View on GitHub (pinned to c5cad058c7)
Solutions
- Register a working MeterProvider before redisotel.Init
- Inspect the wrapped underlying error for the SDK-specific cause
- Review stream-lag histogram options (explicit buckets) for SDK incompatibilities
- Disable the stream metrics group in config if not needed
Example fix
// before client, err := redis.NewClient(opt) redisotel.Init(client) // mp already shut down // after mp := sdkmetric.NewMeterProvider() defer mp.Shutdown(context.Background()) otel.SetMeterProvider(mp) redisotel.Init(client)
Defensive patterns
Strategy: validation
Validate before calling
mp := sdkmetric.NewMeterProvider()
otel.SetMeterProvider(mp)
// then
if err := redisotel.Init(client); err != nil {
log.Fatalf("metrics init failed: %v", err)
} Try / catch
if err := redisotel.Init(client); err != nil {
if strings.Contains(err.Error(), "stream lag histogram") {
// fall back to no metrics
log.Printf("stream-lag metrics disabled: %v", err)
}
} Prevention
- Initialize metrics SDK before instrumenting
- Validate explicit histogram bucket options against the SDK version
- Disable stream metric group if streams are unused
When it happens
Trigger: redisotel.Init called with the stream metric group enabled and meter.Float64Histogram(MetricStreamLag, streamLagOpts...) returns an error from the OTel SDK.
Common situations: MeterProvider shutdown or not registered; explicit bucket boundaries passed via options rejected by the SDK; duplicate instrument creation with conflicting attributes/units in some SDK versions.
Related errors
- failed to create connection create time histogram: %w
- failed to create connection wait time histogram: %w
- failed to create metrics recorder: %w
- failed to create operation duration histogram: %w
- failed to create connection count metric: %w
AI-assisted analysis of redis/go-redis@c5cad058c7 (2026-09-01).
Data as JSON: /api/errors/0a4b9a6e3730ea15.
Report an issue: GitHub.