vectordotdev/vector · error
Failed type coercion
Error message
Failed type coercion, {self:?} is not a trace event What it means
`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.
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
Example fix
// before
let trace = event.as_trace();
// after
let trace = match &event {
Event::Trace(t) => t,
_ => return Ok(()),
}; Defensive patterns
Strategy: type-guard
Validate before calling
if !matches!(event, Event::Trace(_)) { return; } Type guard
fn is_trace(e: &Event) -> bool { matches!(e, Event::Trace(_)) } Prevention
- Match on the Event enum before coercion
When it happens
Trigger: Calling `event.as_trace()` on a non-trace event, e.g. trace-oriented codecs or sinks (like datadog traces) receiving log or metric events.
Common situations: 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.
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
- Failed type coercion
- Failed type coercion
- Failed type coercion
- Failed type coercion
- Failed type coercion
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/0d09a3e86e1867c5.
Report an issue: GitHub.
Appendix: source
Thrown at lib/vector-core/src/event/mod.rs:226
/// Fallibly coerces self into a `Metric`
///
/// If the event is a `Metric`, then `Some(metric)` is returned, otherwise `None`.
pub fn try_into_metric(self) -> Option<Metric> {
match self {
Event::Metric(metric) => Some(metric),
_ => None,
}
}
/// Return self as a `TraceEvent`
///
/// # Panics
///
/// This function panics if self is anything other than an `Event::Trace`.
pub fn as_trace(&self) -> &TraceEvent {
match self {
Event::Trace(trace) => trace,
_ => panic!("Failed type coercion, {self:?} is not a trace event"),
}
}
/// Return self as a mutable `TraceEvent`
///
/// # Panics
///
/// This function panics if self is anything other than an `Event::Trace`.
pub fn as_mut_trace(&mut self) -> &mut TraceEvent {
match self {
Event::Trace(trace) => trace,
_ => panic!("Failed type coercion, {self:?} is not a trace event"),
}
}
/// Coerces self into a `TraceEvent`
///
/// # PanicsView on GitHub (pinned to bdb87aeaa4)