{"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/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-core/src/event/mod.rs#L106-L142","documentation":"`Event` is an enum over `Log`, `Metric` and `Trace`, and `Event::as_log` (lib/vector-core/src/event/mod.rs:119-125) is the infallible-looking borrow conversion that only works on `Event::Log`. Any other variant panics with a debug dump of the event. The `# Panics` doc states the precondition; the fallible twin `try_into_log` exists for code that cannot guarantee the variant.","triggerScenarios":"Calling `event.as_log()` on an event produced by a metrics source (`host_metrics`, `prometheus_scrape`, `internal_metrics`) or a trace source (`opentelemetry`), e.g. a log-oriented transform or sink written against `&LogEvent` that receives `Event::Metric`/`Event::Trace` from the topology.","commonSituations":"Adding a metrics source to a pipeline whose sinks/transforms assume logs (e.g. routing `internal_metrics` into a log-only transform); custom components that call `as_log` on every incoming event without checking; multiplexed pipelines where a route transform is missing so mixed event types reach log consumers.","solutions":["Match on the variant or use the fallible API: `event.try_into_log()`, handling `None` by skipping or erroring that event.","Fix the topology: add a `filter`/`route` transform (or correct source/sink wiring) so only log events reach components that call `as_log`.","If writing a component, declare its accepted input types in the component traits so the topology validates it at config-load time."],"exampleFix":"// before\nlet log = event.as_log(); // panics on Event::Metric/Event::Trace\n\n// after\nmatch event {\n    Event::Log(log) => handle_log(&log),\n    Event::Metric(m) => handle_metric(&m),\n    Event::Trace(t) => handle_trace(&t),\n}\n// or fallibly: let Some(log) = event.try_into_log() else { return Ok(()) };","handlingStrategy":"type-guard","validationCode":"if matches!(event, Event::Log(_)) {\n    let log = event.as_log();\n    // safe: guarded\n}","typeGuard":"fn is_log_event(e: &Event) -> bool { matches!(e, Event::Log(_)) }","tryCatchPattern":null,"preventionTips":["Default to try_into_log()/variant matching in any component receiving events from the topology.","Reserve as_log() for call sites where the component trait already guarantees log input.","Test every component with all three event variants."],"tags":["rust","vector","event","type-coercion","panic"],"backgroundTag":"event-type-coercion-failure","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}