Skip to content

Commit

Permalink
test a multi chain cause
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Oct 23, 2024
1 parent 6ee492d commit 78c8da7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions emitter/otlp/src/data/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,30 @@ mod tests {
fn encode_err_stacktrace() {
#[derive(Debug)]
struct Error {
source: Option<std::io::Error>,
msg: &'static str,
source: Option<Box<dyn std::error::Error + 'static>>,
}

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "something went wrong")
std::fmt::Display::fmt(self.msg, f)
}
}

impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.source
.as_ref()
.map(|source| source as &(dyn std::error::Error + 'static))
.map(|source| &**source)
}
}

let err = Error {
source: Some(std::io::Error::new(std::io::ErrorKind::Other, "IO error")),
msg: "something went wrong",
source: Some(Box::new(Error {
msg: "there was a problem",
source: Some(Box::new(std::io::Error::new(std::io::ErrorKind::Other, "IO error"))),
})),
};

encode_event::<LogsEventEncoder>(emit::evt!("failed: {err}", err), |buf| {
Expand All @@ -199,7 +204,7 @@ mod tests {

assert_eq!("exception.stacktrace", de.attributes[0].key);
assert_eq!(
Some(string_value("caused by: IO error")),
Some(string_value("caused by: there was a problem\ncaused by: IO error")),
de.attributes[0].value
);

Expand All @@ -210,7 +215,7 @@ mod tests {
);
});

let err = Error { source: None };
let err = Error { msg: "something went wrong", source: None };

encode_event::<LogsEventEncoder>(emit::evt!("failed: {err}", err), |buf| {
let de = logs::LogRecord::decode(buf).unwrap();
Expand Down

0 comments on commit 78c8da7

Please sign in to comment.