Skip to content

Commit 959d576

Browse files
committed
Fix build
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
1 parent 014caec commit 959d576

7 files changed

Lines changed: 68 additions & 22 deletions

File tree

cbindgen.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rename_types = "PascalCase"
2323
"PushTagResult" = "ddog_Vec_Tag_PushResult"
2424
"ZendString" = "_zend_string"
2525
"FILE" = "FILE"
26+
"EndpointConfig" = "ddog_crasht_EndpointConfig"
2627

2728
[enum]
2829
prefix_with_name = true

components-rs/common.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
# define DDOG_CHECK_RETURN
4040
#endif
4141

42+
#ifdef _WIN32
43+
#define LIBDD_DLLIMPORT __declspec(dllimport)
44+
#else
45+
#define LIBDD_DLLIMPORT
46+
#endif
47+
4248
/**
4349
* Default value for the timeout field in milliseconds.
4450
*/
@@ -1283,6 +1289,14 @@ typedef struct ddog_crasht_Slice_CharSlice {
12831289
uintptr_t len;
12841290
} ddog_crasht_Slice_CharSlice;
12851291

1292+
typedef struct ddog_crasht_EndpointConfig {
1293+
ddog_CharSlice url;
1294+
ddog_CharSlice api_key;
1295+
ddog_CharSlice test_token;
1296+
uint64_t timeout;
1297+
bool use_system_resolver;
1298+
} ddog_crasht_EndpointConfig;
1299+
12861300
typedef struct ddog_crasht_Slice_I32 {
12871301
/**
12881302
* Should be non-null and suitably aligned for the underlying type. It is
@@ -1305,7 +1319,7 @@ typedef struct ddog_crasht_Config {
13051319
* The endpoint to send the crash report to (can be a file://).
13061320
* If None, the crashtracker will infer the agent host from env variables.
13071321
*/
1308-
ddog_CharSlice endpoint;
1322+
struct ddog_crasht_EndpointConfig endpoint;
13091323
/**
13101324
* Optional filename for a unix domain socket if the receiver is used asynchonously
13111325
*/

components-rs/ddtrace.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ void ddtrace_drop_rust_string(char *input, uintptr_t len);
3939

4040
struct ddog_Endpoint *ddtrace_parse_agent_url(ddog_CharSlice url);
4141

42+
void ddtrace_endpoint_as_crashtracker_config(const struct ddog_Endpoint *endpoint,
43+
void (*callback)(ddog_crasht_EndpointConfig, void*),
44+
void *userdata);
45+
4246
ddog_Configurator *ddog_library_configurator_new_dummy(bool debug_logs, ddog_CharSlice language);
4347

4448
int posix_spawn_file_actions_addchdir_np(void *file_actions, const char *path);

components-rs/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ pub unsafe extern "C" fn ddtrace_parse_agent_url(
101101
})
102102
}
103103

104+
#[no_mangle]
105+
pub unsafe extern "C" fn ddtrace_endpoint_as_crashtracker_config(
106+
endpoint: &Endpoint,
107+
callback: unsafe extern "C" fn(EndpointConfig<'_>, *mut std::ffi::c_void),
108+
userdata: *mut std::ffi::c_void,
109+
) {
110+
let url_str = endpoint.url.to_string();
111+
unsafe {
112+
callback(
113+
EndpointConfig {
114+
url: CharSlice::from(url_str.as_str()),
115+
api_key: CharSlice::from(endpoint.api_key.as_deref().unwrap_or("")),
116+
test_token: CharSlice::from(endpoint.test_token.as_deref().unwrap_or("")),
117+
timeout: endpoint.timeout_ms,
118+
use_system_resolver: endpoint.use_system_resolver,
119+
},
120+
userdata,
121+
);
122+
}
123+
}
124+
104125
// Hack: Without this, the PECL build of the tracer does not contain the ddog_library_* functions
105126
// It works well without in the "normal" build
106127
#[no_mangle]

components-rs/telemetry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use hashbrown::{Equivalent, HashMap};
55
use std::collections::HashSet;
66
use std::ffi::CString;
77
use std::path::PathBuf;
8-
use std::time::{Duration, Instant, SystemTime};
8+
use std::time::{Duration, SystemTime};
99

1010
use datadog_ipc::platform::NamedShmHandle;
1111
use datadog_sidecar::one_way_shared_memory::{open_named_shm, OneWayShmReader};

ext/signals.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,20 @@ static void dd_crasht_add_opcache_inis(ddog_Vec_Tag *tags) {
242242
#endif
243243
}
244244

245+
typedef struct {
246+
ddog_crasht_Config config;
247+
ddog_crasht_Metadata metadata;
248+
} dd_crasht_init_args;
249+
250+
static void dd_crasht_do_init(ddog_crasht_EndpointConfig endpoint_config, void *userdata) {
251+
dd_crasht_init_args *args = (dd_crasht_init_args *)userdata;
252+
args->config.endpoint = endpoint_config;
253+
dd_crashtracker_check_result(
254+
ddog_crasht_init_without_receiver(args->config, args->metadata),
255+
"Cannot initialize CrashTracker"
256+
);
257+
}
258+
245259
static void dd_init_crashtracker() {
246260
ddog_CharSlice socket_path = ddog_sidecar_get_crashtracker_unix_socket_path();
247261
if (socket_path.len > sizeof(crashtracker_socket_path) - 1) {
@@ -256,32 +270,24 @@ static void dd_init_crashtracker() {
256270
free((void *) socket_path.ptr);
257271
socket_path.ptr = crashtracker_socket_path;
258272

259-
char *agent_url = ddtrace_agent_url();
260-
if (!agent_url) {
273+
if (!ddtrace_endpoint) {
261274
return;
262275
}
263276

264-
ddog_crasht_Config config = {
265-
.endpoint = {.ptr = agent_url, .len = strlen(agent_url)},
266-
.timeout_ms = 5000,
267-
.resolve_frames = DDOG_CRASHT_STACKTRACE_COLLECTION_ENABLED_WITH_INPROCESS_SYMBOLS,
268-
.optional_unix_socket_filename = socket_path,
269-
.additional_files = {0},
270-
};
271-
272277
ddog_Vec_Tag tags = ddog_Vec_Tag_new();
273278
dd_crasht_add_opcache_inis(&tags);
274279

275-
const ddog_crasht_Metadata metadata = ddtrace_setup_crashtracking_metadata(&tags);
280+
dd_crasht_init_args args = {
281+
.config = {
282+
.timeout_ms = 5000,
283+
.resolve_frames = DDOG_CRASHT_STACKTRACE_COLLECTION_ENABLED_WITH_INPROCESS_SYMBOLS,
284+
.optional_unix_socket_filename = socket_path,
285+
.additional_files = {0},
286+
},
287+
.metadata = ddtrace_setup_crashtracking_metadata(&tags),
288+
};
276289

277-
dd_crashtracker_check_result(
278-
ddog_crasht_init_without_receiver(
279-
config,
280-
metadata
281-
),
282-
"Cannot initialize CrashTracker"
283-
);
284-
free(agent_url);
290+
ddtrace_endpoint_as_crashtracker_config(ddtrace_endpoint, dd_crasht_do_init, &args);
285291

286292
ddtrace_register_crashtracking_frames_collection();
287293

0 commit comments

Comments
 (0)