Skip to content

Commit cde7cfe

Browse files
committed
refactor: use import instead of qualified path
1 parent d49c469 commit cde7cfe

File tree

1 file changed

+56
-54
lines changed

1 file changed

+56
-54
lines changed

libdd-data-pipeline-ffi/src/trace_exporter.rs

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
use crate::error::{ExporterError, ExporterErrorCode as ErrorCode};
55
use crate::response::ExporterResponse;
6+
use crate::{catch_panic, gen_error};
67
use libdd_common_ffi::{
78
CharSlice,
89
{slice::AsBytes, slice::ByteSlice},
910
};
11+
1012
use libdd_data_pipeline::trace_exporter::{
1113
TelemetryConfig, TraceExporter, TraceExporterInputFormat, TraceExporterOutputFormat,
1214
};
@@ -71,7 +73,7 @@ pub struct TraceExporterConfig {
7173
pub unsafe extern "C" fn ddog_trace_exporter_config_new(
7274
out_handle: NonNull<Box<TraceExporterConfig>>,
7375
) {
74-
crate::catch_panic!(
76+
catch_panic!(
7577
out_handle
7678
.as_ptr()
7779
.write(Box::<TraceExporterConfig>::default()),
@@ -91,17 +93,17 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_url(
9193
config: Option<&mut TraceExporterConfig>,
9294
url: CharSlice,
9395
) -> Option<Box<ExporterError>> {
94-
crate::catch_panic!(
96+
catch_panic!(
9597
if let Some(handle) = config {
9698
handle.url = match sanitize_string(url) {
9799
Ok(s) => Some(s),
98100
Err(e) => return Some(e),
99101
};
100102
None
101103
} else {
102-
crate::gen_error!(ErrorCode::InvalidArgument)
104+
gen_error!(ErrorCode::InvalidArgument)
103105
},
104-
crate::gen_error!(ErrorCode::Panic)
106+
gen_error!(ErrorCode::Panic)
105107
)
106108
}
107109

@@ -111,17 +113,17 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_tracer_version(
111113
config: Option<&mut TraceExporterConfig>,
112114
version: CharSlice,
113115
) -> Option<Box<ExporterError>> {
114-
crate::catch_panic!(
116+
catch_panic!(
115117
if let Option::Some(handle) = config {
116118
handle.tracer_version = match sanitize_string(version) {
117119
Ok(s) => Some(s),
118120
Err(e) => return Some(e),
119121
};
120122
None
121123
} else {
122-
crate::gen_error!(ErrorCode::InvalidArgument)
124+
gen_error!(ErrorCode::InvalidArgument)
123125
},
124-
crate::gen_error!(ErrorCode::Panic)
126+
gen_error!(ErrorCode::Panic)
125127
)
126128
}
127129

@@ -131,17 +133,17 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_language(
131133
config: Option<&mut TraceExporterConfig>,
132134
lang: CharSlice,
133135
) -> Option<Box<ExporterError>> {
134-
crate::catch_panic!(
136+
catch_panic!(
135137
if let Option::Some(handle) = config {
136138
handle.language = match sanitize_string(lang) {
137139
Ok(s) => Some(s),
138140
Err(e) => return Some(e),
139141
};
140142
None
141143
} else {
142-
crate::gen_error!(ErrorCode::InvalidArgument)
144+
gen_error!(ErrorCode::InvalidArgument)
143145
},
144-
crate::gen_error!(ErrorCode::Panic)
146+
gen_error!(ErrorCode::Panic)
145147
)
146148
}
147149

@@ -151,17 +153,17 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_lang_version(
151153
config: Option<&mut TraceExporterConfig>,
152154
version: CharSlice,
153155
) -> Option<Box<ExporterError>> {
154-
crate::catch_panic!(
156+
catch_panic!(
155157
if let Option::Some(handle) = config {
156158
handle.language_version = match sanitize_string(version) {
157159
Ok(s) => Some(s),
158160
Err(e) => return Some(e),
159161
};
160162
None
161163
} else {
162-
crate::gen_error!(ErrorCode::InvalidArgument)
164+
gen_error!(ErrorCode::InvalidArgument)
163165
},
164-
crate::gen_error!(ErrorCode::Panic)
166+
gen_error!(ErrorCode::Panic)
165167
)
166168
}
167169

@@ -171,17 +173,17 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_lang_interpreter(
171173
config: Option<&mut TraceExporterConfig>,
172174
interpreter: CharSlice,
173175
) -> Option<Box<ExporterError>> {
174-
crate::catch_panic!(
176+
catch_panic!(
175177
if let Option::Some(handle) = config {
176178
handle.language_interpreter = match sanitize_string(interpreter) {
177179
Ok(s) => Some(s),
178180
Err(e) => return Some(e),
179181
};
180182
None
181183
} else {
182-
crate::gen_error!(ErrorCode::InvalidArgument)
184+
gen_error!(ErrorCode::InvalidArgument)
183185
},
184-
crate::gen_error!(ErrorCode::Panic)
186+
gen_error!(ErrorCode::Panic)
185187
)
186188
}
187189

@@ -191,17 +193,17 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_hostname(
191193
config: Option<&mut TraceExporterConfig>,
192194
hostname: CharSlice,
193195
) -> Option<Box<ExporterError>> {
194-
crate::catch_panic!(
196+
catch_panic!(
195197
if let Option::Some(handle) = config {
196198
handle.hostname = match sanitize_string(hostname) {
197199
Ok(s) => Some(s),
198200
Err(e) => return Some(e),
199201
};
200202
None
201203
} else {
202-
crate::gen_error!(ErrorCode::InvalidArgument)
204+
gen_error!(ErrorCode::InvalidArgument)
203205
},
204-
crate::gen_error!(ErrorCode::Panic)
206+
gen_error!(ErrorCode::Panic)
205207
)
206208
}
207209

@@ -211,17 +213,17 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_env(
211213
config: Option<&mut TraceExporterConfig>,
212214
env: CharSlice,
213215
) -> Option<Box<ExporterError>> {
214-
crate::catch_panic!(
216+
catch_panic!(
215217
if let Option::Some(handle) = config {
216218
handle.env = match sanitize_string(env) {
217219
Ok(s) => Some(s),
218220
Err(e) => return Some(e),
219221
};
220222
None
221223
} else {
222-
crate::gen_error!(ErrorCode::InvalidArgument)
224+
gen_error!(ErrorCode::InvalidArgument)
223225
},
224-
crate::gen_error!(ErrorCode::Panic)
226+
gen_error!(ErrorCode::Panic)
225227
)
226228
}
227229

@@ -230,17 +232,17 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_version(
230232
config: Option<&mut TraceExporterConfig>,
231233
version: CharSlice,
232234
) -> Option<Box<ExporterError>> {
233-
crate::catch_panic!(
235+
catch_panic!(
234236
if let Option::Some(handle) = config {
235237
handle.version = match sanitize_string(version) {
236238
Ok(s) => Some(s),
237239
Err(e) => return Some(e),
238240
};
239241
None
240242
} else {
241-
crate::gen_error!(ErrorCode::InvalidArgument)
243+
gen_error!(ErrorCode::InvalidArgument)
242244
},
243-
crate::gen_error!(ErrorCode::Panic)
245+
gen_error!(ErrorCode::Panic)
244246
)
245247
}
246248

@@ -250,17 +252,17 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_service(
250252
config: Option<&mut TraceExporterConfig>,
251253
service: CharSlice,
252254
) -> Option<Box<ExporterError>> {
253-
crate::catch_panic!(
255+
catch_panic!(
254256
if let Option::Some(handle) = config {
255257
handle.service = match sanitize_string(service) {
256258
Ok(s) => Some(s),
257259
Err(e) => return Some(e),
258260
};
259261
None
260262
} else {
261-
crate::gen_error!(ErrorCode::InvalidArgument)
263+
gen_error!(ErrorCode::InvalidArgument)
262264
},
263-
crate::gen_error!(ErrorCode::Panic)
265+
gen_error!(ErrorCode::Panic)
264266
)
265267
}
266268

@@ -270,14 +272,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_health_metrics(
270272
config: Option<&mut TraceExporterConfig>,
271273
is_enabled: bool,
272274
) -> Option<Box<ExporterError>> {
273-
crate::catch_panic!(
275+
catch_panic!(
274276
if let Option::Some(config) = config {
275277
config.health_metrics_enabled = is_enabled;
276278
None
277279
} else {
278-
crate::gen_error!(ErrorCode::InvalidArgument)
280+
gen_error!(ErrorCode::InvalidArgument)
279281
},
280-
crate::gen_error!(ErrorCode::Panic)
282+
gen_error!(ErrorCode::Panic)
281283
)
282284
}
283285

@@ -287,7 +289,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_telemetry(
287289
config: Option<&mut TraceExporterConfig>,
288290
telemetry_cfg: Option<&TelemetryClientConfig>,
289291
) -> Option<Box<ExporterError>> {
290-
crate::catch_panic!(
292+
catch_panic!(
291293
if let Option::Some(config) = config {
292294
if let Option::Some(telemetry_cfg) = telemetry_cfg {
293295
let cfg = TelemetryConfig {
@@ -303,9 +305,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_telemetry(
303305
}
304306
None
305307
} else {
306-
crate::gen_error!(ErrorCode::InvalidArgument)
308+
gen_error!(ErrorCode::InvalidArgument)
307309
},
308-
crate::gen_error!(ErrorCode::Panic)
310+
gen_error!(ErrorCode::Panic)
309311
)
310312
}
311313

@@ -315,14 +317,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_compute_stats(
315317
config: Option<&mut TraceExporterConfig>,
316318
is_enabled: bool,
317319
) -> Option<Box<ExporterError>> {
318-
crate::catch_panic!(
320+
catch_panic!(
319321
if let Option::Some(config) = config {
320322
config.compute_stats = is_enabled;
321323
None
322324
} else {
323-
crate::gen_error!(ErrorCode::InvalidArgument)
325+
gen_error!(ErrorCode::InvalidArgument)
324326
},
325-
crate::gen_error!(ErrorCode::Panic)
327+
gen_error!(ErrorCode::Panic)
326328
)
327329
}
328330

@@ -343,14 +345,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_client_computed_stats(
343345
config: Option<&mut TraceExporterConfig>,
344346
client_computed_stats: bool,
345347
) -> Option<Box<ExporterError>> {
346-
crate::catch_panic!(
348+
catch_panic!(
347349
if let Option::Some(config) = config {
348350
config.client_computed_stats = client_computed_stats;
349351
None
350352
} else {
351-
crate::gen_error!(ErrorCode::InvalidArgument)
353+
gen_error!(ErrorCode::InvalidArgument)
352354
},
353-
crate::gen_error!(ErrorCode::Panic)
355+
gen_error!(ErrorCode::Panic)
354356
)
355357
}
356358

@@ -360,17 +362,17 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_test_session_token(
360362
config: Option<&mut TraceExporterConfig>,
361363
token: CharSlice,
362364
) -> Option<Box<ExporterError>> {
363-
crate::catch_panic!(
365+
catch_panic!(
364366
if let Option::Some(handle) = config {
365367
handle.test_session_token = match sanitize_string(token) {
366368
Ok(s) => Some(s),
367369
Err(e) => return Some(e),
368370
};
369371
None
370372
} else {
371-
crate::gen_error!(ErrorCode::InvalidArgument)
373+
gen_error!(ErrorCode::InvalidArgument)
372374
},
373-
crate::gen_error!(ErrorCode::Panic)
375+
gen_error!(ErrorCode::Panic)
374376
)
375377
}
376378

@@ -380,14 +382,14 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_set_connection_timeout(
380382
config: Option<&mut TraceExporterConfig>,
381383
timeout_ms: u64,
382384
) -> Option<Box<ExporterError>> {
383-
crate::catch_panic!(
385+
catch_panic!(
384386
if let Option::Some(handle) = config {
385387
handle.connection_timeout = Some(timeout_ms);
386388
None
387389
} else {
388-
crate::gen_error!(ErrorCode::InvalidArgument)
390+
gen_error!(ErrorCode::InvalidArgument)
389391
},
390-
crate::gen_error!(ErrorCode::Panic)
392+
gen_error!(ErrorCode::Panic)
391393
)
392394
}
393395

@@ -402,7 +404,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_new(
402404
out_handle: NonNull<Box<TraceExporter>>,
403405
config: Option<&TraceExporterConfig>,
404406
) -> Option<Box<ExporterError>> {
405-
crate::catch_panic!(
407+
catch_panic!(
406408
if let Some(config) = config {
407409
// let config = &*ptr;
408410
let mut builder = TraceExporter::builder();
@@ -451,9 +453,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_new(
451453
Err(err) => Some(Box::new(ExporterError::from(err))),
452454
}
453455
} else {
454-
crate::gen_error!(ErrorCode::InvalidArgument)
456+
gen_error!(ErrorCode::InvalidArgument)
455457
},
456-
crate::gen_error!(ErrorCode::Panic)
458+
gen_error!(ErrorCode::Panic)
457459
)
458460
}
459461

@@ -464,7 +466,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_new(
464466
/// * handle - The handle to the TraceExporter instance.
465467
#[no_mangle]
466468
pub unsafe extern "C" fn ddog_trace_exporter_free(handle: Box<TraceExporter>) {
467-
let _ = crate::catch_panic!(handle.shutdown(None), Ok(()));
469+
let _ = catch_panic!(handle.shutdown(None), Ok(()));
468470
}
469471

470472
/// Send traces to the Datadog Agent.
@@ -485,10 +487,10 @@ pub unsafe extern "C" fn ddog_trace_exporter_send(
485487
) -> Option<Box<ExporterError>> {
486488
let exporter = match handle {
487489
Some(exp) => exp,
488-
None => return crate::gen_error!(ErrorCode::InvalidArgument),
490+
None => return gen_error!(ErrorCode::InvalidArgument),
489491
};
490492

491-
crate::catch_panic!(
493+
catch_panic!(
492494
match exporter.send(&trace) {
493495
Ok(resp) => {
494496
if let Some(result) = response_out {
@@ -500,7 +502,7 @@ pub unsafe extern "C" fn ddog_trace_exporter_send(
500502
}
501503
Err(e) => Some(Box::new(ExporterError::from(e))),
502504
},
503-
crate::gen_error!(ErrorCode::Panic)
505+
gen_error!(ErrorCode::Panic)
504506
)
505507
}
506508

@@ -1100,7 +1102,7 @@ mod tests {
11001102
#[cfg(all(feature = "catch_panic", panic = "unwind"))]
11011103
#[test]
11021104
fn catch_panic_test() {
1103-
let ret = crate::catch_panic!(panic!("Panic!"), crate::gen_error!(ErrorCode::Panic));
1105+
let ret = catch_panic!(panic!("Panic!"), gen_error!(ErrorCode::Panic));
11041106

11051107
assert!(ret.is_some());
11061108
assert_eq!(ret.unwrap().code, ErrorCode::Panic);

0 commit comments

Comments
 (0)