{"record":{"id":"9c19fb2378e75629","repo":"redis/go-redis","slug":"failed-to-create-connection-closed-metric-w","errorCode":null,"errorMessage":"failed to create connection closed metric: %w","messagePattern":"failed to create connection closed metric: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extra/redisotel-native/redisotel.go","lineNumber":292,"sourceCode":"\t\tif cfg.histAggregation == HistogramAggregationExplicitBucket {\n\t\t\tconnectionWaitTimeOpts = append(connectionWaitTimeOpts,\n\t\t\t\tmetric.WithExplicitBucketBoundaries(cfg.bucketsConnectionWaitTime...),\n\t\t\t)\n\t\t}\n\t\tvar connectionWaitTimeConv dbconv.ClientConnectionWaitTime\n\t\tconnectionWaitTimeConv, err = dbconv.NewClientConnectionWaitTime(meter, connectionWaitTimeOpts...)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create connection wait time histogram: %w\", err)\n\t\t}\n\t\tconnectionWaitTime = connectionWaitTimeConv.Inst()\n\n\t\tconnectionClosed, err = meter.Int64Counter(\n\t\t\tMetricConnectionClosed,\n\t\t\tmetric.WithDescription(\"The number of connections that have been closed\"),\n\t\t\tmetric.WithUnit(\"{connection}\"),\n\t\t)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create connection closed metric: %w\", err)\n\t\t}\n\n\t\tconnectionPendingReqs, err = meter.Int64UpDownCounter(\n\t\t\tdbconv.ClientConnectionPendingRequests{}.Name(),\n\t\t\tmetric.WithDescription(dbconv.ClientConnectionPendingRequests{}.Description()),\n\t\t\tmetric.WithUnit(dbconv.ClientConnectionPendingRequests{}.Unit()),\n\t\t)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create connection pending requests metric: %w\", err)\n\t\t}\n\t}\n\n\tvar pubsubMessages metric.Int64Counter\n\n\tif cfg.isMetricGroupEnabled(MetricGroupPubSub) {\n\t\tpubsubMessages, err = meter.Int64Counter(\n\t\t\tMetricPubSubMessages,\n\t\t\tmetric.WithDescription(\"The number of Pub/Sub messages sent or received\"),","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/extra/redisotel-native/redisotel.go#L274-L310","documentation":"Returned by createRecorder when meter.Int64Counter fails to create the redis.client.connection.closed counter, which tracks the number of closed pool connections. Init aborts and observability remains uninitialized. As with the other recorder errors, the MeterProvider refused to register the instrument.","triggerScenarios":"Init with MetricGroupFlagConnectionAdvanced enabled while the MeterProvider is stopped or misconfigured; a strict provider that rejects the instrument name/unit ({connection}); duplicate registration by another package.","commonSituations":"Metric-name collisions when both extra/redisprometheus and redisotel-native are initialized; ordering issues where telemetry teardown precedes client init; buggy custom MeterProvider implementations.","solutions":["Confirm the MeterProvider passed in Config.MeterProvider (or the global one) is operational before Init","Remove or rename any duplicate registration of redis.client.connection.closed","Inspect the wrapped error for the provider's reason and fix the provider setup","Keep a single metrics solution or ensure names/units do not collide across packages","Clear MetricGroupFlagConnectionAdvanced in Config.MetricGroups as an isolation step or workaround"],"exampleFix":"// before\nerr := obs.Init(&redisotel.Config{Enabled: true, MetricGroups: redisotel.MetricGroupFlagConnectionAdvanced})\n// after\nif err := obs.Init(&redisotel.Config{Enabled: true, MetricGroups: redisotel.MetricGroupFlagConnectionAdvanced, MeterProvider: liveProvider}); err != nil {\n    log.Fatalf(\"redisotel init: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"if cfg.MetricGroups&redisotel.MetricGroupFlagConnectionAdvanced != 0 && cfg.MeterProvider == nil && otel.GetMeterProvider() == nil {\n    return errors.New(\"no meter provider configured\")\n}","typeGuard":null,"tryCatchPattern":"if err := obs.Init(cfg); err != nil {\n    log.Printf(\"redisotel init failed: %v\", err)\n    // run without metrics rather than crashing\n}","preventionTips":["Ensure exactly one metrics package registers redis.client.connection.closed","Initialize telemetry before Redis clients","Log Init errors","Keep the provider alive until after obs.Shutdown()"],"tags":["opentelemetry","metrics","connection-pool","go"],"backgroundTag":"otel-instrument-creation-failed","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}