From eb62a6ddc43f41d37a78a7273c7bfc93a8450d04 Mon Sep 17 00:00:00 2001 From: Daniel Schwartz-Narbonne Date: Fri, 26 Jul 2024 14:20:11 -0400 Subject: [PATCH] [crashtracker] Use common Endpoint to further decouple from profiler (#549) --- ddcommon-ffi/src/endpoint.rs | 7 +++++++ examples/ffi/crashtracking.c | 12 +++++++++--- profiling-ffi/cbindgen.toml | 1 + .../src/crashtracker/collector/datatypes.rs | 5 ++--- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ddcommon-ffi/src/endpoint.rs b/ddcommon-ffi/src/endpoint.rs index 6f3c6f4a8..6477e23d2 100644 --- a/ddcommon-ffi/src/endpoint.rs +++ b/ddcommon-ffi/src/endpoint.rs @@ -15,6 +15,13 @@ pub extern "C" fn ddog_endpoint_from_url(url: crate::CharSlice) -> Option Option> { + let url = format!("file://{}", filename.to_utf8_lossy()); + Some(Box::new(Endpoint::from_slice(&url))) +} + // We'll just specify the base site here. If api key provided, different intakes need to use their // own subdomains. #[no_mangle] diff --git a/examples/ffi/crashtracking.c b/examples/ffi/crashtracking.c index 13f4a99c8..63725a919 100644 --- a/examples/ffi/crashtracking.c +++ b/examples/ffi/crashtracking.c @@ -49,11 +49,15 @@ int main(int argc, char **argv) { .optional_stdout_filename = DDOG_CHARSLICE_C("/tmp/crashreports/stdout.txt"), }; + struct ddog_Endpoint *endpoint = + ddog_endpoint_from_filename(DDOG_CHARSLICE_C("/tmp/crashreports/crashreport.json")); + // Alternatively: + // struct ddog_Endpoint * endpoint = + // ddog_endpoint_from_url(DDOG_CHARSLICE_C("http://localhost:8126")); + ddog_prof_CrashtrackerConfiguration config = { .create_alt_stack = false, - .endpoint = ddog_Endpoint_file(DDOG_CHARSLICE_C("/tmp/crashreports/crashreport.json")), - // Alternatively: - //.endpoint = ddog_prof_Endpoint_agent(DDOG_CHARSLICE_C("http://localhost:8126")), + .endpoint = endpoint, .resolve_frames = DDOG_PROF_STACKTRACE_COLLECTION_ENABLED_WITH_INPROCESS_SYMBOLS, }; @@ -65,6 +69,8 @@ int main(int argc, char **argv) { }; handle_result(ddog_prof_Crashtracker_init_with_receiver(config, receiver_config, metadata)); + ddog_endpoint_drop(endpoint); + handle_result( ddog_prof_Crashtracker_begin_profiling_op(DDOG_PROF_PROFILING_OP_TYPES_SERIALIZING)); handle_uintptr_t_result(ddog_prof_Crashtracker_insert_span_id(0, 42)); diff --git a/profiling-ffi/cbindgen.toml b/profiling-ffi/cbindgen.toml index be9db9fcd..4c3c485dd 100644 --- a/profiling-ffi/cbindgen.toml +++ b/profiling-ffi/cbindgen.toml @@ -23,6 +23,7 @@ renaming_overrides_prefixing = true "ByteSlice" = "ddog_ByteSlice" "CancellationToken" = "ddog_CancellationToken" "CharSlice" = "ddog_CharSlice" +"Endpoint" = "ddog_Endpoint" "Error" = "ddog_Error" "HttpStatus" = "ddog_HttpStatus" "Slice_CChar" = "ddog_Slice_CChar" diff --git a/profiling-ffi/src/crashtracker/collector/datatypes.rs b/profiling-ffi/src/crashtracker/collector/datatypes.rs index e7f55a4a1..4fe817e59 100644 --- a/profiling-ffi/src/crashtracker/collector/datatypes.rs +++ b/profiling-ffi/src/crashtracker/collector/datatypes.rs @@ -1,7 +1,6 @@ // Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 -use crate::exporter::{self, ProfilingEndpoint}; use crate::option_from_char_slice; pub use datadog_crashtracker::{ProfilingOpTypes, StacktraceCollection}; use ddcommon_ffi::slice::{AsBytes, CharSlice}; @@ -67,7 +66,7 @@ pub struct CrashtrackerConfiguration<'a> { /// /// If ProfilingEndpoint is left to a zero value (enum value for Agent + empty charslice), /// the crashtracker will infer the agent host from env variables. - pub endpoint: ProfilingEndpoint<'a>, + pub endpoint: Option<&'a ddcommon::Endpoint>, pub resolve_frames: StacktraceCollection, pub timeout_secs: u64, pub wait_for_receiver: bool, @@ -86,7 +85,7 @@ impl<'a> TryFrom> vec }; let create_alt_stack = value.create_alt_stack; - let endpoint = unsafe { exporter::try_to_endpoint(value.endpoint).ok() }; + let endpoint = value.endpoint.cloned(); let resolve_frames = value.resolve_frames; let wait_for_receiver = value.wait_for_receiver; Self::new(