{"record":{"id":"0d09a3e86e1867c5","repo":"vectordotdev/vector","slug":"failed-type-coercion-self-is-not-a-trace-even","errorCode":null,"errorMessage":"Failed type coercion, {self:?} is not a trace event","messagePattern":"Failed type coercion, (.+?) is not a trace event","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-core/src/event/mod.rs","lineNumber":226,"sourceCode":"    /// Fallibly coerces self into a `Metric`\n    ///\n    /// If the event is a `Metric`, then `Some(metric)` is returned, otherwise `None`.\n    pub fn try_into_metric(self) -> Option<Metric> {\n        match self {\n            Event::Metric(metric) => Some(metric),\n            _ => None,\n        }\n    }\n\n    /// Return self as a `TraceEvent`\n    ///\n    /// # Panics\n    ///\n    /// This function panics if self is anything other than an `Event::Trace`.\n    pub fn as_trace(&self) -> &TraceEvent {\n        match self {\n            Event::Trace(trace) => trace,\n            _ => panic!(\"Failed type coercion, {self:?} is not a trace event\"),\n        }\n    }\n\n    /// Return self as a mutable `TraceEvent`\n    ///\n    /// # Panics\n    ///\n    /// This function panics if self is anything other than an `Event::Trace`.\n    pub fn as_mut_trace(&mut self) -> &mut TraceEvent {\n        match self {\n            Event::Trace(trace) => trace,\n            _ => panic!(\"Failed type coercion, {self:?} is not a trace event\"),\n        }\n    }\n\n    /// Coerces self into a `TraceEvent`\n    ///\n    /// # Panics","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-core/src/event/mod.rs#L208-L244","documentation":"`Event::as_trace` borrows the event as a `TraceEvent` and panics if the variant is `Log` or `Metric`. Trace processing code expects trace events; anything else is an invariant violation reported via panic with the event's Debug representation.","triggerScenarios":"Calling `event.as_trace()` on a non-trace event, e.g. trace-oriented codecs or sinks (like datadog traces) receiving log or metric events.","commonSituations":"A trace pipeline misconfigured to accept a log source, shared encoder code invoked for all event kinds, and tests that build events with the wrong variant.","solutions":["Check `matches!(event, Event::Trace(_))` before borrowing","Use the fallible `try_as_trace`-style accessor for generic code","Fix routing so trace-only components receive only trace streams"],"exampleFix":"// before\nlet trace = event.as_trace();\n// after\nlet trace = match &event {\n    Event::Trace(t) => t,\n    _ => return Ok(()),\n};","handlingStrategy":"type-guard","validationCode":"if !matches!(event, Event::Trace(_)) { return; }","typeGuard":"fn is_trace(e: &Event) -> bool { matches!(e, Event::Trace(_)) }","tryCatchPattern":null,"preventionTips":["Match on the Event enum before coercion"],"tags":["rust","panic","type-coercion","trace"],"backgroundTag":"type-mismatch","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}