{"record":{"id":"3bea56280fdb7f97","repo":"influxdata/influxdb","slug":"no-metric-in-progress","errorCode":null,"errorMessage":"no metric in progress","messagePattern":"no metric in progress","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/metric_exporters/src/lib.rs","lineNumber":75,"sourceCode":"            MetricKind::DurationCounter => {\n                (format!(\"{metric_name}_seconds_total\"), MetricType::COUNTER)\n            }\n            MetricKind::DurationGauge => (format!(\"{metric_name}_seconds\"), MetricType::GAUGE),\n            MetricKind::DurationHistogram => {\n                (format!(\"{metric_name}_seconds\"), MetricType::HISTOGRAM)\n            }\n        };\n\n        let mut metric = MetricFamily::default();\n        metric.set_name(name);\n        metric.set_help(description.to_string());\n        metric.set_field_type(metric_type);\n\n        self.metric = Some((metric, false))\n    }\n\n    fn report_observation(&mut self, attributes: &Attributes, observation: Observation) {\n        let (metrics, used) = self.metric.as_mut().expect(\"no metric in progress\");\n\n        let metrics = metrics.mut_metric();\n\n        let mut metric = Metric::default();\n\n        metric.set_label(\n            attributes\n                .iter()\n                .map(|(name, value)| {\n                    let mut pair = LabelPair::default();\n                    pair.set_name(name.to_string());\n                    pair.set_value(value.to_string());\n                    pair\n                })\n                .collect(),\n        );\n\n        match observation {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/influxdata/influxdb/blob/d28e26e048401c53cbb98cf2d6ab0cf1e98048ca/core/metric_exporters/src/lib.rs#L57-L93","documentation":"PrometheusTextEncoder (core/metric_exporters) implements metric::Reporter for the Prometheus text exposition format. start_metric opens a metric family (stored as Option<(MetricFamily, bool)>), report_observation appends labeled samples, and finishing closes it. report_observation panics with 'no metric in progress' when no start_metric is active - called before start_metric or after the family was finished. (Symmetrically, start_metric asserts 'metric already in progress' if the previous family was never finished.)","triggerScenarios":"Hand-driving the encoder out of order: report_observation without a preceding start_metric; reporting after the current family was finished; replaying observations captured from another reporter without replaying the start_metric call first.","commonSituations":"Writing custom exporters that wrap or buffer the Prometheus encoder; refactors that reorder start/report/finish; batch export logic that drops the start call for empty attribute sets.","solutions":["Emit the full ordered sequence per metric: start_metric, one or more report_observation, then finish","When buffering/replaying observations, buffer the (name, description, kind) triple too and replay start_metric first","Wrap the encoder in a struct that tracks 'metric open' state and asserts or logs before misordering","Reuse the stock export paths in the metric crate rather than driving the trait by hand"],"exampleFix":"// before\nencoder.report_observation(&attrs, obs);  // no start_metric -> panic\n\n// after\nencoder.start_metric(\"requests\", \"count\", MetricKind::U64Counter);\nencoder.report_observation(&attrs, obs);\n// finish_metric() when done\n","handlingStrategy":"validation","validationCode":"// when replaying buffered observations, replay start_metric first\nfor (meta, obs) in buffered {\n    encoder.start_metric(meta.name, meta.description, meta.kind);\n    for (attrs, observation) in obs {\n        encoder.report_observation(&attrs, observation);\n    }\n    // finish per your Reporter impl's contract\n}\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Emit start/report/finish in strict order for every metric family","Buffer the (name, description, kind) triple alongside observations so replay is complete","Wrap encoders in a state-tracking struct that rejects out-of-order calls"],"tags":["metrics","prometheus","exporter","state-machine","panic","influxdb3"],"backgroundTag":"metric-reporter-state-violation","analyzedSha":"d28e26e048401c53cbb98cf2d6ab0cf1e98048ca","analyzedAt":"2026-08-16T19:53:34.623Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}