Skip to content

Commit eb62a6d

Browse files
authored
[crashtracker] Use common Endpoint to further decouple from profiler (#549)
1 parent 32d5eae commit eb62a6d

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

ddcommon-ffi/src/endpoint.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ pub extern "C" fn ddog_endpoint_from_url(url: crate::CharSlice) -> Option<Box<En
1515
.map(|url| Box::new(Endpoint::from_url(url)))
1616
}
1717

18+
#[no_mangle]
19+
#[must_use]
20+
pub extern "C" fn ddog_endpoint_from_filename(filename: crate::CharSlice) -> Option<Box<Endpoint>> {
21+
let url = format!("file://{}", filename.to_utf8_lossy());
22+
Some(Box::new(Endpoint::from_slice(&url)))
23+
}
24+
1825
// We'll just specify the base site here. If api key provided, different intakes need to use their
1926
// own subdomains.
2027
#[no_mangle]

examples/ffi/crashtracking.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@ int main(int argc, char **argv) {
4949
.optional_stdout_filename = DDOG_CHARSLICE_C("/tmp/crashreports/stdout.txt"),
5050
};
5151

52+
struct ddog_Endpoint *endpoint =
53+
ddog_endpoint_from_filename(DDOG_CHARSLICE_C("/tmp/crashreports/crashreport.json"));
54+
// Alternatively:
55+
// struct ddog_Endpoint * endpoint =
56+
// ddog_endpoint_from_url(DDOG_CHARSLICE_C("http://localhost:8126"));
57+
5258
ddog_prof_CrashtrackerConfiguration config = {
5359
.create_alt_stack = false,
54-
.endpoint = ddog_Endpoint_file(DDOG_CHARSLICE_C("/tmp/crashreports/crashreport.json")),
55-
// Alternatively:
56-
//.endpoint = ddog_prof_Endpoint_agent(DDOG_CHARSLICE_C("http://localhost:8126")),
60+
.endpoint = endpoint,
5761
.resolve_frames = DDOG_PROF_STACKTRACE_COLLECTION_ENABLED_WITH_INPROCESS_SYMBOLS,
5862
};
5963

@@ -65,6 +69,8 @@ int main(int argc, char **argv) {
6569
};
6670

6771
handle_result(ddog_prof_Crashtracker_init_with_receiver(config, receiver_config, metadata));
72+
ddog_endpoint_drop(endpoint);
73+
6874
handle_result(
6975
ddog_prof_Crashtracker_begin_profiling_op(DDOG_PROF_PROFILING_OP_TYPES_SERIALIZING));
7076
handle_uintptr_t_result(ddog_prof_Crashtracker_insert_span_id(0, 42));

profiling-ffi/cbindgen.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ renaming_overrides_prefixing = true
2323
"ByteSlice" = "ddog_ByteSlice"
2424
"CancellationToken" = "ddog_CancellationToken"
2525
"CharSlice" = "ddog_CharSlice"
26+
"Endpoint" = "ddog_Endpoint"
2627
"Error" = "ddog_Error"
2728
"HttpStatus" = "ddog_HttpStatus"
2829
"Slice_CChar" = "ddog_Slice_CChar"

profiling-ffi/src/crashtracker/collector/datatypes.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::exporter::{self, ProfilingEndpoint};
54
use crate::option_from_char_slice;
65
pub use datadog_crashtracker::{ProfilingOpTypes, StacktraceCollection};
76
use ddcommon_ffi::slice::{AsBytes, CharSlice};
@@ -67,7 +66,7 @@ pub struct CrashtrackerConfiguration<'a> {
6766
///
6867
/// If ProfilingEndpoint is left to a zero value (enum value for Agent + empty charslice),
6968
/// the crashtracker will infer the agent host from env variables.
70-
pub endpoint: ProfilingEndpoint<'a>,
69+
pub endpoint: Option<&'a ddcommon::Endpoint>,
7170
pub resolve_frames: StacktraceCollection,
7271
pub timeout_secs: u64,
7372
pub wait_for_receiver: bool,
@@ -86,7 +85,7 @@ impl<'a> TryFrom<CrashtrackerConfiguration<'a>>
8685
vec
8786
};
8887
let create_alt_stack = value.create_alt_stack;
89-
let endpoint = unsafe { exporter::try_to_endpoint(value.endpoint).ok() };
88+
let endpoint = value.endpoint.cloned();
9089
let resolve_frames = value.resolve_frames;
9190
let wait_for_receiver = value.wait_for_receiver;
9291
Self::new(

0 commit comments

Comments
 (0)