use crate::dynamic::message_chain;
use crate::fail::{Fail, Fault, Level, Rejection};
use crate::profile::{LaneProfile, Slot};
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_fail<D: Rejection, L: LaneProfile>(span: &tracing::Span, f: &Fail<D, L>) {
span.record("error", true);
span.record("error.lane", f.lane().as_str());
match f {
Fail::Rejected(d) => {
span.record("error.code", Into::<&'static str>::into(d.code()));
span.record("error.level", level_str(d.level()));
}
Fail::Denied(_) => {
span.record("error.code", "FORBIDDEN");
span.record("error.level", "WARN");
}
Fail::Transient(t) => {
span.record("error.code", t.marker().kind.as_str());
span.record("error.level", "INFO");
span.record("exception.message", message_chain(t));
}
Fail::Fatal(x) => {
span.record("error.code", x.marker().kind.as_str());
span.record("error.level", "ERROR");
span.record("exception.message", message_chain(x));
span.record("exception.type", x.marker().kind.as_str());
}
}
}
pub(crate) fn record_fault<L: LaneProfile>(span: &tracing::Span, f: &Fault<L>) {
span.record("error", true);
span.record("error.lane", f.lane().as_str());
match f {
Fault::Denied(_) => {
span.record("error.code", "FORBIDDEN");
span.record("error.level", "WARN");
}
Fault::Transient(t) => {
span.record("error.code", t.marker().kind.as_str());
span.record("error.level", "INFO");
span.record("exception.message", message_chain(t));
}
Fault::Fatal(x) => {
span.record("error.code", x.marker().kind.as_str());
span.record("error.level", "ERROR");
span.record("exception.message", message_chain(x));
span.record("exception.type", x.marker().kind.as_str());
}
}
}