use crate::carrier::{LaneRef, LaneRejected};
use crate::dynamic::message_chain;
use crate::fail::Level;
pub const FIELDS: &[&str] = &[
"error",
"error.lane",
"error.code",
"error.level",
"exception.message",
"exception.type",
];
fn level_str(level: Level) -> &'static str {
match level {
Level::Trace => "TRACE",
Level::Debug => "DEBUG",
Level::Info => "INFO",
Level::Warn => "WARN",
Level::Error => "ERROR",
}
}
pub(crate) fn record_lanes<R: LaneRejected>(span: &tracing::Span, lane: LaneRef<'_, R>) {
span.record("error", true);
span.record("error.lane", lane.lane().as_str());
match lane {
LaneRef::Rejected(d) => {
span.record("error.code", d.code_str());
span.record("error.level", level_str(d.level()));
}
LaneRef::Denied(_) => {
span.record("error.code", "FORBIDDEN");
span.record("error.level", "WARN");
}
LaneRef::Transient(t) => {
span.record("error.code", t.kind.as_str());
span.record("error.level", "INFO");
span.record("exception.message", message_chain(t));
}
LaneRef::Fatal(x) => {
span.record("error.code", x.kind.as_str());
span.record("error.level", "ERROR");
span.record("exception.message", message_chain(x));
span.record("exception.type", x.kind.as_str());
}
}
}