{"id":"299a311ac8c3077e","repo":"go-redis/redis","slug":"failed-to-create-metrics-recorder-w","errorCode":null,"errorMessage":"failed to create metrics recorder: %w","messagePattern":"failed to create metrics recorder: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extra/redisotel-native/redisotel.go","lineNumber":100,"sourceCode":"\tif !cfg.Enabled {\n\t\treturn nil\n\t}\n\n\t// Get meter provider (use global if not provided)\n\tmeterProvider := cfg.MeterProvider\n\tif meterProvider == nil {\n\t\tmeterProvider = otel.GetMeterProvider()\n\t}\n\n\tmeter := meterProvider.Meter(\n\t\t\"github.com/redis/go-redis\",\n\t\tmetric.WithInstrumentationVersion(redis.Version()),\n\t)\n\n\tinternalCfg := o.configToInternal(cfg)\n\trecorder, err := o.createRecorder(meter, internalCfg)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create metrics recorder: %w\", err)\n\t}\n\n\to.recorder = recorder\n\to.initialized = true\n\tredis.SetOTelRecorder(recorder)\n\n\treturn nil\n}\n\n// IsEnabled returns true if observability is initialized and enabled.\nfunc (o *ObservabilityInstance) IsEnabled() bool {\n\to.mu.RLock()\n\tdefer o.mu.RUnlock()\n\treturn o.initialized && o.config != nil && o.config.Enabled\n}\n\n// Shutdown cleans up resources and flushes any pending metrics.\n// This should be called at application shutdown.","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/extra/redisotel-native/redisotel.go#L82-L118","documentation":"Returned by ObservabilityInstance.Init (redisotel.go:100) when createRecorder fails to build the metricsRecorder. This is the umbrella error wrapping the specific instrument-creation failure that occurred inside createRecorder (one of errors 127-138). It means the entire redisotel-native instrumentation setup failed and no metrics will be collected.","triggerScenarios":"Calling GetObservabilityInstance().Init(cfg) where at least one enabled metric group triggers an OTel SDK instrument-creation error inside createRecorder.","commonSituations":"Another part of the application already registered an instrument with the same name but conflicting metadata (unit, description, or instrument type); the MeterProvider is nil, shut down, or broken; invalid custom bucket boundaries in HistogramAggregation configuration.","solutions":["Inspect the wrapped error via errors.Unwrap to find which specific instrument failed (errors 127-138)","Fix the root cause indicated by the wrapped error (most commonly a duplicate instrument name conflict from another OTel integration)","Ensure the MeterProvider passed via cfg.MeterProvider (or the global provider) is valid and not shut down"],"exampleFix":"// before\nif err := obs.Init(cfg); err != nil {\n    panic(err)\n}\n\n// after\nif err := obs.Init(cfg); err != nil {\n    log.Errorf(\"redisotel init failed: %v\", err)\n    if unwrapped := errors.Unwrap(err); unwrapped != nil {\n        log.Errorf(\"root cause: %v\", unwrapped)\n    }\n    // continue without metrics, or fix the conflict and retry\n}","handlingStrategy":"try-catch","validationCode":"// Verify MeterProvider is non-nil and functional before calling Init\nif cfg.MeterProvider == nil {\n    cfg.MeterProvider = otel.GetMeterProvider()\n}","typeGuard":null,"tryCatchPattern":"if err := obs.Init(cfg); err != nil {\n    log.Errorf(\"redisotel init failed: %v\", err)\n    if root := errors.Unwrap(err); root != nil {\n        log.Errorf(\"root cause: %v\", root)\n    }\n    // degrade gracefully without metrics\n}","preventionTips":["Inspect the wrapped error to identify which specific instrument creation failed","Avoid registering OTel instruments with the same name but conflicting metadata across libraries","Call Init exactly once at startup; call Shutdown before re-initializing"],"tags":["otel","redisotel-native","metrics","initialization","instrument"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}