{"record":{"id":"8c80e41f4dc59fc5","repo":"influxdata/influxdb","slug":"metric-should-be-in-progress","errorCode":null,"errorMessage":"metric should be in progress","messagePattern":"metric should be in progress","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/metric/src/lib.rs","lineNumber":347,"sourceCode":"        &mut self,\n        metric_name: &'static str,\n        description: &'static str,\n        kind: MetricKind,\n    ) {\n        assert!(self.in_progress.is_none(), \"metric already in progress\");\n        self.in_progress = Some(ObservationSet {\n            metric_name,\n            description,\n            kind,\n            observations: Default::default(),\n        })\n    }\n\n    fn report_observation(&mut self, attributes: &Attributes, observation: Observation) {\n        let metric = self\n            .in_progress\n            .as_mut()\n            .expect(\"metric should be in progress\");\n        metric.observations.push((attributes.clone(), observation))\n    }\n\n    fn finish_metric(&mut self) {\n        let metric = self\n            .in_progress\n            .take()\n            .expect(\"metric should be in progress\");\n        self.completed.push(metric)\n    }\n}\n\nimpl RawReporter {\n    /// Returns the observation set for a given metric name if any\n    pub fn metric(&self, metric_name: &str) -> Option<&ObservationSet> {\n        self.observations()\n            .iter()\n            .find(|observation| observation.metric_name == metric_name)","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/influxdata/influxdb/blob/d28e26e048401c53cbb98cf2d6ab0cf1e98048ca/core/metric/src/lib.rs#L329-L365","documentation":"RawReporter in core/metric is an in-memory metric::Reporter: begin_metric opens an ObservationSet, report_observation appends observations to it, finish_metric closes it. report_observation expects an in-progress metric; calling it before any begin_metric (or after the set was finished) leaves in_progress as None and this expect panics.","triggerScenarios":"Hand-driving the reporter out of order: report_observation before begin_metric; report_observation after finish_metric; or a wrapper that skips begin_metric on an error path but still reports.","commonSituations":"Writing custom exporters or test harnesses around the metric crate; refactors that reorder begin/report/finish calls; replaying buffered observations without replaying the begin call.","solutions":["Always call begin_metric(metric_name, description, kind) before any report_observation","Call finish_metric exactly once per begin_metric","Encapsulate the begin/report/finish sequence in an RAII guard or helper so error paths cannot skip begin","If you only need the collected data, read reporter.observations() instead of hand-driving the trait"],"exampleFix":"// before\nreporter.report_observation(&attrs, obs);  // no begin_metric -> panic\n\n// after\nreporter.begin_metric(\"requests\", \"count\", MetricKind::U64Counter);\nreporter.report_observation(&attrs, obs);\nreporter.finish_metric();\n","handlingStrategy":"validation","validationCode":"// enforce ordering with an RAII guard around the reporter\nstruct MetricOpen<'a>(&'a mut RawReporter);\nimpl<'a> MetricOpen<'a> {\n    fn begin(r: &'a mut RawReporter, name: &'static str, desc: &'static str, k: MetricKind) -> Self {\n        r.begin_metric(name, desc, k);\n        Self(r)\n    }\n}\nimpl Drop for MetricOpen<'_> {\n    fn drop(&mut self) { self.0.finish_metric(); }\n}\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always begin_metric before report_observation and finish exactly once","Wrap the sequence in an RAII guard so error paths cannot skip begin","Prefer the crate's built-in export paths over hand-driving the Reporter trait"],"tags":["metrics","reporter","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"}