vectordotdev/vector · error

Failed type coercion

Error message

Failed type coercion, {self:?} is not a log event

What it means

`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.

Solutions

  1. Check the variant first with `matches!(event, Event::Log(_))` or use the fallible `event.as_log_mut()`-style accessors / `try_into_log()`
  2. Route metrics/traces to metric-/trace-appropriate components instead of log-only code paths
  3. In generic code, match on the `Event` enum and handle each variant explicitly

Example fix

// before
let log = event.as_log();
// after
let log = match event {
    Event::Log(log) => log,
    other => { debug!("skipping non-log event: {other:?}"); return; }
};
Defensive patterns

Strategy: type-guard

Validate before calling

if !matches!(event, Event::Log(_)) { return; }

Type guard

fn is_log(e: &Event) -> bool { matches!(e, Event::Log(_)) }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16). Data as JSON: /api/errors/a73cb3fcda053db2. Report an issue: GitHub.

Appendix: source

Thrown at lib/vector-core/src/event/mod.rs:124

    fn get_tags(&self) -> TaggedEventsSent {
        match self {
            Event::Log(log) => log.get_tags(),
            Event::Metric(metric) => metric.get_tags(),
            Event::Trace(trace) => trace.get_tags(),
        }
    }
}

impl Event {
    /// Return self as a `LogEvent`
    ///
    /// # Panics
    ///
    /// This function panics if self is anything other than an `Event::Log`.
    pub fn as_log(&self) -> &LogEvent {
        match self {
            Event::Log(log) => log,
            _ => panic!("Failed type coercion, {self:?} is not a log event"),
        }
    }

    /// Return self as a mutable `LogEvent`
    ///
    /// # Panics
    ///
    /// This function panics if self is anything other than an `Event::Log`.
    pub fn as_mut_log(&mut self) -> &mut LogEvent {
        match self {
            Event::Log(log) => log,
            _ => panic!("Failed type coercion, {self:?} is not a log event"),
        }
    }

    /// Coerces self into a `LogEvent`
    ///
    /// # Panics

View on GitHub (pinned to bdb87aeaa4)