Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions libdd-data-pipeline-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,38 @@
mod error;
mod response;
mod trace_exporter;

#[cfg(all(feature = "catch_panic", panic = "unwind"))]
macro_rules! catch_panic {
($f:expr, $err:expr) => {
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| $f)) {
Ok(ret) => ret,
Err(info) => {
if let Some(s) = info.downcast_ref::<String>() {
error!(error = %ErrorCode::Panic, s);
} else if let Some(s) = info.downcast_ref::<&str>() {
error!(error = %ErrorCode::Panic, s);
} else {
error!(error = %ErrorCode::Panic, "Unable to retrieve panic context");
}
$err
}
}
};
}

#[cfg(any(not(feature = "catch_panic"), panic = "abort"))]
macro_rules! catch_panic {
($f:expr, $err:expr) => {
$f
};
}

macro_rules! gen_error {
($l:expr) => {
Some(Box::new(ExporterError::new($l, &$l.to_string())))
};
}

pub(crate) use catch_panic;
pub(crate) use gen_error;
37 changes: 2 additions & 35 deletions libdd-data-pipeline-ffi/src/trace_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,18 @@

use crate::error::{ExporterError, ExporterErrorCode as ErrorCode};
use crate::response::ExporterResponse;
use crate::{catch_panic, gen_error};
use libdd_common_ffi::{
CharSlice,
{slice::AsBytes, slice::ByteSlice},
};

use libdd_data_pipeline::trace_exporter::{
TelemetryConfig, TraceExporter, TraceExporterInputFormat, TraceExporterOutputFormat,
};
use std::{ptr::NonNull, time::Duration};
use tracing::{debug, error};

#[cfg(all(feature = "catch_panic", panic = "unwind"))]
use std::panic::{catch_unwind, AssertUnwindSafe};

macro_rules! gen_error {
($l:expr) => {
Some(Box::new(ExporterError::new($l, &$l.to_string())))
};
}

#[cfg(all(feature = "catch_panic", panic = "unwind"))]
macro_rules! catch_panic {
($f:expr, $err:expr) => {
match catch_unwind(AssertUnwindSafe(|| $f)) {
Ok(ret) => ret,
Err(info) => {
if let Some(s) = info.downcast_ref::<String>() {
error!(error = %ErrorCode::Panic, s);
} else if let Some(s) = info.downcast_ref::<&str>() {
error!(error = %ErrorCode::Panic, s);
} else {
error!(error = %ErrorCode::Panic, "Unable to retrieve panic context");
}
$err
}
}
};
}

#[cfg(any(not(feature = "catch_panic"), panic = "abort"))]
macro_rules! catch_panic {
($f:expr, $err:expr) => {
$f
};
}

#[inline]
fn sanitize_string(str: CharSlice) -> Result<String, Box<ExporterError>> {
match str.try_to_utf8() {
Expand Down
Loading