redis/go-redis · error
failed to create metrics recorder: %w
Error message
failed to create metrics recorder: %w
What it means
redisotel-native's Init sets up OpenTelemetry metrics instrumentation and creates a metrics recorder from the configured meter. If recorder creation fails (bad metric config, meter provider misconfigured), Init wraps and returns the underlying error via %w. The instrumentation is therefore not enabled and redis.SetOTelRecorder is never called.
Source
Thrown at extra/redisotel-native/redisotel.go:100
if !cfg.Enabled {
return nil
}
// Get meter provider (use global if not provided)
meterProvider := cfg.MeterProvider
if meterProvider == nil {
meterProvider = otel.GetMeterProvider()
}
meter := meterProvider.Meter(
"github.com/redis/go-redis",
metric.WithInstrumentationVersion(redis.Version()),
)
internalCfg := o.configToInternal(cfg)
recorder, err := o.createRecorder(meter, internalCfg)
if err != nil {
return fmt.Errorf("failed to create metrics recorder: %w", err)
}
o.recorder = recorder
o.initialized = true
redis.SetOTelRecorder(recorder)
return nil
}
// IsEnabled returns true if observability is initialized and enabled.
func (o *ObservabilityInstance) IsEnabled() bool {
o.mu.RLock()
defer o.mu.RUnlock()
return o.initialized && o.config != nil && o.config.Enabled
}
// Shutdown cleans up resources and flushes any pending metrics.
// This should be called at application shutdown.View on GitHub (pinned to c5cad058c7)
Solutions
- Unwrap the returned error (%w preserves it) to see the root cause from createRecorder.
- Initialize and register the global/system meter provider (otel.SetMeterProvider) before calling Init.
- Review the InstrumentationMetrics options for invalid values and fix them.
- Ensure Init is called only once per client set of options and the provider is not shutdown mid-run.
Example fix
// before: no meter provider registered err := instrumentor.Init(ctx, cfg) // failed to create metrics recorder: no meter provider // after: set up the provider first provider := sdkmetric.NewMeterProvider() otel.SetMeterProvider(provider) err := instrumentor.Init(ctx, cfg)
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure a meter provider exists before Init
if otel.GetMeterProvider() == otel.GetMeterProvider() &&
os.Getenv("OTEL_SDK_DISABLED") != "true" {
// proceed; otherwise configure sdkmetric provider first
} Try / catch
if err := instrumentor.Init(ctx, cfg); err != nil {
var root error
errors.As(err, &root) // %w chain preserves createRecorder cause
log.Printf("otel init failed: %v", root) // use internal.Logger in lib code
// continue without instrumentation
} Prevention
- Register the OTel meter provider before calling Init
- Do not shut down the provider while the client is running
- Validate InstrumentationMetrics options before Init
- Call Init once during application bootstrap
- Check errors with errors.As/Unwrap to reach the root cause
When it happens
Trigger: Calling Init (public) with an InstrumentationMetrics config whose options make createRecorder fail — e.g. an invalid meter provider, closed provider, or conflicting instrument configuration — at redisotel.go:~100.
Common situations: Meter provider not registered or shut down before Init; invalid metrics options in redisotel.InstrumentMetrics config; duplicate instrument creation with the same name/options; missing OpenTelemetry SDK setup in the app.
Related errors
- failed to create operation duration histogram: %w
- failed to create connection count metric: %w
- failed to create connection handoff metric: %w
- failed to create Pub/Sub messages metric: %w
- failed to create connection create time histogram: %w
AI-assisted analysis of redis/go-redis@c5cad058c7 (2026-09-01).
Data as JSON: /api/errors/145ad67006051b79.
Report an issue: GitHub.