{"record":{"id":"a73cb3fcda053db2","repo":"vectordotdev/vector","slug":"failed-type-coercion-self-is-not-a-log-event","errorCode":null,"errorMessage":"Failed type coercion, {self:?} is not a log event","messagePattern":"Failed type coercion, (.+?) is not a log event","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-core/src/event/mod.rs","lineNumber":124,"sourceCode":"    fn get_tags(&self) -> TaggedEventsSent {\n        match self {\n            Event::Log(log) => log.get_tags(),\n            Event::Metric(metric) => metric.get_tags(),\n            Event::Trace(trace) => trace.get_tags(),\n        }\n    }\n}\n\nimpl Event {\n    /// Return self as a `LogEvent`\n    ///\n    /// # Panics\n    ///\n    /// This function panics if self is anything other than an `Event::Log`.\n    pub fn as_log(&self) -> &LogEvent {\n        match self {\n            Event::Log(log) => log,\n            _ => panic!(\"Failed type coercion, {self:?} is not a log event\"),\n        }\n    }\n\n    /// Return self as a mutable `LogEvent`\n    ///\n    /// # Panics\n    ///\n    /// This function panics if self is anything other than an `Event::Log`.\n    pub fn as_mut_log(&mut self) -> &mut LogEvent {\n        match self {\n            Event::Log(log) => log,\n            _ => panic!(\"Failed type coercion, {self:?} is not a log event\"),\n        }\n    }\n\n    /// Coerces self into a `LogEvent`\n    ///\n    /// # Panics","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-core/src/event/mod.rs#L106-L142","documentation":"`Event::as_log` borrows the event as a `LogEvent` and panics if the variant is anything other than `Event::Log`. The library uses a panic instead of a `Result` because callers are expected to know the event kind (e.g. inside log-only pipelines). The panic message includes the Debug dump of the actual event so you can see which variant you received.","triggerScenarios":"Calling `event.as_log()` on an `Event::Metric` or `Event::Trace`; per the call list this happens in encode/get_timestamp paths, encode_event, and message() when fed a metric or trace event instead of a log event.","commonSituations":"Pipelines or sinks configured for logs receiving metrics (e.g. pointing a log-oriented transform or the `message()` VRL function at a metrics stream), test harnesses feeding mixed event types, or topology routing bugs that let a metric reach a log-only component.","solutions":["Check the variant first with `matches!(event, Event::Log(_))` or use the fallible `event.as_log_mut()`-style accessors / `try_into_log()`","Route metrics/traces to metric-/trace-appropriate components instead of log-only code paths","In generic code, match on the `Event` enum and handle each variant explicitly"],"exampleFix":"// before\nlet log = event.as_log();\n// after\nlet log = match event {\n    Event::Log(log) => log,\n    other => { debug!(\"skipping non-log event: {other:?}\"); return; }\n};","handlingStrategy":"type-guard","validationCode":"if !matches!(event, Event::Log(_)) { return; }","typeGuard":"fn is_log(e: &Event) -> bool { matches!(e, Event::Log(_)) }","tryCatchPattern":null,"preventionTips":["Match on the Event enum before coercion"],"tags":["rust","panic","type-coercion","event"],"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"}