{"record":{"id":"7fd7169b2fc2c7c5","repo":"jaegertracing/jaeger","slug":"cannot-create-metrics-reader-w","errorCode":null,"errorMessage":"cannot create metrics reader %w","messagePattern":"cannot create metrics reader %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/jaeger/internal/extension/jaegerquery/server.go","lineNumber":244,"sourceCode":"\t\treturn nil, nil\n\t}\n\treturn reader, writer\n}\n\nfunc (s *server) createMetricReader(host component.Host) (metricstore.Reader, error) {\n\tif s.config.Storage.Metrics == \"\" {\n\t\ts.telset.Logger.Info(\"Metric storage not configured\")\n\t\treturn disabled.NewMetricsReader()\n\t}\n\n\tmsf, err := jaegerstorage.GetMetricStorageFactory(s.config.Storage.Metrics, host)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot find metrics storage factory: %w\", err)\n\t}\n\n\tmetricsReader, err := msf.CreateMetricsReader()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot create metrics reader %w\", err)\n\t}\n\n\treturn metricsReader, nil\n}\n\nfunc (s *server) Shutdown(_ context.Context) error {\n\tif s.aiHealth != nil {\n\t\ts.aiHealth.Stop()\n\t}\n\tif s.server != nil {\n\t\treturn s.server.Close()\n\t}\n\treturn nil\n}\n\n// QueryService returns the v2 query service instance.\nfunc (s *server) QueryService() *querysvc.QueryService {\n\treturn s.qs","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/cmd/jaeger/internal/extension/jaegerquery/server.go#L226-L262","documentation":"The jaegerquery extension calls createMetricReader to build the metrics reader that backs /metrics-queries endpoints. When storage.Metrics is configured, it fetches a MetricStoreFactory from the jaegerstorage extension and calls CreateMetricsReader(); any error from that call (failed backend client construction, bad config, unsupported backend) is wrapped with 'cannot create metrics reader %w'. Note the format string lacks ':w' separation, so the wrapped error is concatenated directly to the message text.","triggerScenarios":"server.Start -> createMetricReader when config.Storage.Metrics names a declared metric backend but msf.CreateMetricsReader() fails — e.g. the Prometheus/Elasticsearch/OpenSearch/ClickHouse factory cannot build its client or its configuration is invalid at reader construction time.","commonSituations":"Misconfigured metric storage section (bad endpoint URL, unreachable Elasticsearch/Prometheus settings validated late), referencing a metric backend whose config passed Validate() but fails at factory level, or typo'd backend fields that only surface when the reader is instantiated.","solutions":["Inspect the concatenated inner error text for the real cause and fix the metric backend configuration under the named storage entry","Verify the backend named in query.storage.metrics is declared under jaegerstorage.metric_backends and uses a supported type (prometheus/elasticsearch/opensearch/clickhouse)","Test backend connectivity/credentials from the jaeger host; ensure version compatibility with the configured metric store","Enable debug logging on the jaegerstorage extension to see 'Initializing metrics storage' context before the failure"],"exampleFix":"// before (confusing concatenated message)\nfmt.Errorf(\"cannot create metrics reader %w\", err)\n// after (properly separated wrap)\nfmt.Errorf(\"cannot create metrics reader: %w\", err)","handlingStrategy":"try-catch","validationCode":"// verify metric storage is declared before starting query\nif _, err := jaegerstorage.GetMetricStorageFactory(cfg.Storage.Metrics, host); err != nil {\n    return fmt.Errorf(\"metrics storage misconfigured: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := srv.Start(ctx, host); err != nil {\n    var inner error\n    if errors.Unwrap(err) != nil {\n        inner = errors.Unwrap(err)\n    }\n    telset.Logger.Error(\"query start failed creating metrics reader\",\n        zap.Error(err), zap.NamedError(\"cause\", inner))\n    return err\n}","preventionTips":["Declare the metric backend under jaegerstorage.metric_backends before wiring query.storage.metrics","Validate the full collector config (otelcol validate) before startup","Check backend connectivity and credentials in the deploy environment"],"tags":["go","jaeger","metrics","startup"],"backgroundTag":"metrics-reader-init-failed","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}