From d49c469155e4def628e522c17c4f08e8e6407899 Mon Sep 17 00:00:00 2001 From: paullegranddc Date: Tue, 10 Mar 2026 12:31:50 +0100 Subject: [PATCH 1/2] refactor(data-pipeline-ffi): move macro definitions for better reuse # Motivation So these macros can be used in other modules. --- libdd-data-pipeline-ffi/src/lib.rs | 35 +++++ libdd-data-pipeline-ffi/src/trace_exporter.rs | 143 +++++++----------- 2 files changed, 89 insertions(+), 89 deletions(-) diff --git a/libdd-data-pipeline-ffi/src/lib.rs b/libdd-data-pipeline-ffi/src/lib.rs index d85002ab40..9e4e4bc278 100644 --- a/libdd-data-pipeline-ffi/src/lib.rs +++ b/libdd-data-pipeline-ffi/src/lib.rs @@ -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::() { + 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; diff --git a/libdd-data-pipeline-ffi/src/trace_exporter.rs b/libdd-data-pipeline-ffi/src/trace_exporter.rs index 20a3f380f0..c9bf9abe7f 100644 --- a/libdd-data-pipeline-ffi/src/trace_exporter.rs +++ b/libdd-data-pipeline-ffi/src/trace_exporter.rs @@ -13,41 +13,6 @@ use libdd_data_pipeline::trace_exporter::{ 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::() { - 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> { match str.try_to_utf8() { @@ -106,7 +71,7 @@ pub struct TraceExporterConfig { pub unsafe extern "C" fn ddog_trace_exporter_config_new( out_handle: NonNull>, ) { - catch_panic!( + crate::catch_panic!( out_handle .as_ptr() .write(Box::::default()), @@ -126,7 +91,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_url( config: Option<&mut TraceExporterConfig>, url: CharSlice, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Some(handle) = config { handle.url = match sanitize_string(url) { Ok(s) => Some(s), @@ -134,9 +99,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_url( }; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -146,7 +111,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_tracer_version( config: Option<&mut TraceExporterConfig>, version: CharSlice, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(handle) = config { handle.tracer_version = match sanitize_string(version) { Ok(s) => Some(s), @@ -154,9 +119,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_tracer_version( }; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -166,7 +131,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_language( config: Option<&mut TraceExporterConfig>, lang: CharSlice, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(handle) = config { handle.language = match sanitize_string(lang) { Ok(s) => Some(s), @@ -174,9 +139,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_language( }; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -186,7 +151,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_lang_version( config: Option<&mut TraceExporterConfig>, version: CharSlice, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(handle) = config { handle.language_version = match sanitize_string(version) { Ok(s) => Some(s), @@ -194,9 +159,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_lang_version( }; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -206,7 +171,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_lang_interpreter( config: Option<&mut TraceExporterConfig>, interpreter: CharSlice, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(handle) = config { handle.language_interpreter = match sanitize_string(interpreter) { Ok(s) => Some(s), @@ -214,9 +179,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_lang_interpreter( }; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -226,7 +191,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_hostname( config: Option<&mut TraceExporterConfig>, hostname: CharSlice, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(handle) = config { handle.hostname = match sanitize_string(hostname) { Ok(s) => Some(s), @@ -234,9 +199,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_hostname( }; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -246,7 +211,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_env( config: Option<&mut TraceExporterConfig>, env: CharSlice, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(handle) = config { handle.env = match sanitize_string(env) { Ok(s) => Some(s), @@ -254,9 +219,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_env( }; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -265,7 +230,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_version( config: Option<&mut TraceExporterConfig>, version: CharSlice, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(handle) = config { handle.version = match sanitize_string(version) { Ok(s) => Some(s), @@ -273,9 +238,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_version( }; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -285,7 +250,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_service( config: Option<&mut TraceExporterConfig>, service: CharSlice, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(handle) = config { handle.service = match sanitize_string(service) { Ok(s) => Some(s), @@ -293,9 +258,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_service( }; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -305,14 +270,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_health_metrics( config: Option<&mut TraceExporterConfig>, is_enabled: bool, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(config) = config { config.health_metrics_enabled = is_enabled; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -322,7 +287,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_telemetry( config: Option<&mut TraceExporterConfig>, telemetry_cfg: Option<&TelemetryClientConfig>, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(config) = config { if let Option::Some(telemetry_cfg) = telemetry_cfg { let cfg = TelemetryConfig { @@ -338,9 +303,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_telemetry( } None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -350,14 +315,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_compute_stats( config: Option<&mut TraceExporterConfig>, is_enabled: bool, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(config) = config { config.compute_stats = is_enabled; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -378,14 +343,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_client_computed_stats( config: Option<&mut TraceExporterConfig>, client_computed_stats: bool, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(config) = config { config.client_computed_stats = client_computed_stats; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -395,7 +360,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_test_session_token( config: Option<&mut TraceExporterConfig>, token: CharSlice, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(handle) = config { handle.test_session_token = match sanitize_string(token) { Ok(s) => Some(s), @@ -403,9 +368,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_test_session_token( }; None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -415,14 +380,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_connection_timeout( config: Option<&mut TraceExporterConfig>, timeout_ms: u64, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Option::Some(handle) = config { handle.connection_timeout = Some(timeout_ms); None } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -437,7 +402,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_new( out_handle: NonNull>, config: Option<&TraceExporterConfig>, ) -> Option> { - catch_panic!( + crate::catch_panic!( if let Some(config) = config { // let config = &*ptr; let mut builder = TraceExporter::builder(); @@ -486,9 +451,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_new( Err(err) => Some(Box::new(ExporterError::from(err))), } } else { - gen_error!(ErrorCode::InvalidArgument) + crate::gen_error!(ErrorCode::InvalidArgument) }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -499,7 +464,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_new( /// * handle - The handle to the TraceExporter instance. #[no_mangle] pub unsafe extern "C" fn ddog_trace_exporter_free(handle: Box) { - let _ = catch_panic!(handle.shutdown(None), Ok(())); + let _ = crate::catch_panic!(handle.shutdown(None), Ok(())); } /// Send traces to the Datadog Agent. @@ -520,10 +485,10 @@ pub unsafe extern "C" fn ddog_trace_exporter_send( ) -> Option> { let exporter = match handle { Some(exp) => exp, - None => return gen_error!(ErrorCode::InvalidArgument), + None => return crate::gen_error!(ErrorCode::InvalidArgument), }; - catch_panic!( + crate::catch_panic!( match exporter.send(&trace) { Ok(resp) => { if let Some(result) = response_out { @@ -535,7 +500,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_send( } Err(e) => Some(Box::new(ExporterError::from(e))), }, - gen_error!(ErrorCode::Panic) + crate::gen_error!(ErrorCode::Panic) ) } @@ -1135,7 +1100,7 @@ mod tests { #[cfg(all(feature = "catch_panic", panic = "unwind"))] #[test] fn catch_panic_test() { - let ret = catch_panic!(panic!("Panic!"), gen_error!(ErrorCode::Panic)); + let ret = crate::catch_panic!(panic!("Panic!"), crate::gen_error!(ErrorCode::Panic)); assert!(ret.is_some()); assert_eq!(ret.unwrap().code, ErrorCode::Panic); From cde7cfeebfd10d5d32227f272b0e23ca8ca6e3d4 Mon Sep 17 00:00:00 2001 From: paullegranddc Date: Tue, 10 Mar 2026 16:06:55 +0100 Subject: [PATCH 2/2] refactor: use import instead of qualified path --- libdd-data-pipeline-ffi/src/trace_exporter.rs | 110 +++++++++--------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/libdd-data-pipeline-ffi/src/trace_exporter.rs b/libdd-data-pipeline-ffi/src/trace_exporter.rs index c9bf9abe7f..27226a00dd 100644 --- a/libdd-data-pipeline-ffi/src/trace_exporter.rs +++ b/libdd-data-pipeline-ffi/src/trace_exporter.rs @@ -3,10 +3,12 @@ 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, }; @@ -71,7 +73,7 @@ pub struct TraceExporterConfig { pub unsafe extern "C" fn ddog_trace_exporter_config_new( out_handle: NonNull>, ) { - crate::catch_panic!( + catch_panic!( out_handle .as_ptr() .write(Box::::default()), @@ -91,7 +93,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_url( config: Option<&mut TraceExporterConfig>, url: CharSlice, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Some(handle) = config { handle.url = match sanitize_string(url) { Ok(s) => Some(s), @@ -99,9 +101,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_url( }; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -111,7 +113,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_tracer_version( config: Option<&mut TraceExporterConfig>, version: CharSlice, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(handle) = config { handle.tracer_version = match sanitize_string(version) { Ok(s) => Some(s), @@ -119,9 +121,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_tracer_version( }; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -131,7 +133,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_language( config: Option<&mut TraceExporterConfig>, lang: CharSlice, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(handle) = config { handle.language = match sanitize_string(lang) { Ok(s) => Some(s), @@ -139,9 +141,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_language( }; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -151,7 +153,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_lang_version( config: Option<&mut TraceExporterConfig>, version: CharSlice, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(handle) = config { handle.language_version = match sanitize_string(version) { Ok(s) => Some(s), @@ -159,9 +161,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_lang_version( }; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -171,7 +173,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_lang_interpreter( config: Option<&mut TraceExporterConfig>, interpreter: CharSlice, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(handle) = config { handle.language_interpreter = match sanitize_string(interpreter) { Ok(s) => Some(s), @@ -179,9 +181,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_lang_interpreter( }; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -191,7 +193,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_hostname( config: Option<&mut TraceExporterConfig>, hostname: CharSlice, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(handle) = config { handle.hostname = match sanitize_string(hostname) { Ok(s) => Some(s), @@ -199,9 +201,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_hostname( }; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -211,7 +213,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_env( config: Option<&mut TraceExporterConfig>, env: CharSlice, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(handle) = config { handle.env = match sanitize_string(env) { Ok(s) => Some(s), @@ -219,9 +221,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_env( }; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -230,7 +232,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_version( config: Option<&mut TraceExporterConfig>, version: CharSlice, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(handle) = config { handle.version = match sanitize_string(version) { Ok(s) => Some(s), @@ -238,9 +240,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_version( }; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -250,7 +252,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_service( config: Option<&mut TraceExporterConfig>, service: CharSlice, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(handle) = config { handle.service = match sanitize_string(service) { Ok(s) => Some(s), @@ -258,9 +260,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_service( }; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -270,14 +272,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_health_metrics( config: Option<&mut TraceExporterConfig>, is_enabled: bool, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(config) = config { config.health_metrics_enabled = is_enabled; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -287,7 +289,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_telemetry( config: Option<&mut TraceExporterConfig>, telemetry_cfg: Option<&TelemetryClientConfig>, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(config) = config { if let Option::Some(telemetry_cfg) = telemetry_cfg { let cfg = TelemetryConfig { @@ -303,9 +305,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_telemetry( } None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -315,14 +317,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_compute_stats( config: Option<&mut TraceExporterConfig>, is_enabled: bool, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(config) = config { config.compute_stats = is_enabled; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -343,14 +345,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_client_computed_stats( config: Option<&mut TraceExporterConfig>, client_computed_stats: bool, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(config) = config { config.client_computed_stats = client_computed_stats; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -360,7 +362,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_test_session_token( config: Option<&mut TraceExporterConfig>, token: CharSlice, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(handle) = config { handle.test_session_token = match sanitize_string(token) { Ok(s) => Some(s), @@ -368,9 +370,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_test_session_token( }; None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -380,14 +382,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_connection_timeout( config: Option<&mut TraceExporterConfig>, timeout_ms: u64, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Option::Some(handle) = config { handle.connection_timeout = Some(timeout_ms); None } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -402,7 +404,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_new( out_handle: NonNull>, config: Option<&TraceExporterConfig>, ) -> Option> { - crate::catch_panic!( + catch_panic!( if let Some(config) = config { // let config = &*ptr; let mut builder = TraceExporter::builder(); @@ -451,9 +453,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_new( Err(err) => Some(Box::new(ExporterError::from(err))), } } else { - crate::gen_error!(ErrorCode::InvalidArgument) + gen_error!(ErrorCode::InvalidArgument) }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -464,7 +466,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_new( /// * handle - The handle to the TraceExporter instance. #[no_mangle] pub unsafe extern "C" fn ddog_trace_exporter_free(handle: Box) { - let _ = crate::catch_panic!(handle.shutdown(None), Ok(())); + let _ = catch_panic!(handle.shutdown(None), Ok(())); } /// Send traces to the Datadog Agent. @@ -485,10 +487,10 @@ pub unsafe extern "C" fn ddog_trace_exporter_send( ) -> Option> { let exporter = match handle { Some(exp) => exp, - None => return crate::gen_error!(ErrorCode::InvalidArgument), + None => return gen_error!(ErrorCode::InvalidArgument), }; - crate::catch_panic!( + catch_panic!( match exporter.send(&trace) { Ok(resp) => { if let Some(result) = response_out { @@ -500,7 +502,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_send( } Err(e) => Some(Box::new(ExporterError::from(e))), }, - crate::gen_error!(ErrorCode::Panic) + gen_error!(ErrorCode::Panic) ) } @@ -1100,7 +1102,7 @@ mod tests { #[cfg(all(feature = "catch_panic", panic = "unwind"))] #[test] fn catch_panic_test() { - let ret = crate::catch_panic!(panic!("Panic!"), crate::gen_error!(ErrorCode::Panic)); + let ret = catch_panic!(panic!("Panic!"), gen_error!(ErrorCode::Panic)); assert!(ret.is_some()); assert_eq!(ret.unwrap().code, ErrorCode::Panic);