Skip to content

Commit 2846753

Browse files
committed
Don't pass in runtime type
1 parent 7b66803 commit 2846753

File tree

3 files changed

+16
-192
lines changed

3 files changed

+16
-192
lines changed

datadog-crashtracker-ffi/src/runtime_callback.rs

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
//! This module provides C-compatible FFI bindings for registering runtime-specific
77
//! crash callbacks that can provide stack traces for dynamic languages.
88
use datadog_crashtracker::{
9-
get_registered_callback_type_ptr, get_registered_runtime_type_ptr,
10-
is_runtime_callback_registered, register_runtime_stack_callback, CallbackError, CallbackType,
11-
RuntimeStackCallback, RuntimeType,
9+
get_registered_callback_type_ptr, is_runtime_callback_registered,
10+
register_runtime_stack_callback, CallbackError, CallbackType, RuntimeStackCallback,
1211
};
1312

1413
// Re-export the enums for C/C++ consumers
1514
pub use datadog_crashtracker::CallbackType as ddog_CallbackType;
16-
pub use datadog_crashtracker::RuntimeType as ddog_RuntimeType;
1715

1816
pub use datadog_crashtracker::RuntimeStackFrame as ddog_RuntimeStackFrame;
1917

@@ -75,7 +73,6 @@ impl From<CallbackError> for CallbackResult {
7573
///
7674
/// ddog_CallbackResult result = ddog_crasht_register_runtime_stack_callback(
7775
/// my_runtime_callback,
78-
/// RuntimeType::Ruby,
7976
/// CallbackType::Frame,
8077
/// );
8178
/// ```
@@ -86,7 +83,6 @@ impl From<CallbackError> for CallbackResult {
8683
///
8784
/// # Arguments
8885
/// - `callback`: The callback function to invoke during crashes
89-
/// - `runtime_type`: Runtime type enum (Python, Ruby, Php, Nodejs, Unknown)
9086
/// - `callback_type`: Callback type enum (Frame, StacktraceString)
9187
///
9288
/// # Returns
@@ -99,10 +95,9 @@ impl From<CallbackError> for CallbackResult {
9995
#[no_mangle]
10096
pub unsafe extern "C" fn ddog_crasht_register_runtime_stack_callback(
10197
callback: RuntimeStackCallback,
102-
runtime_type: RuntimeType,
10398
callback_type: CallbackType,
10499
) -> CallbackResult {
105-
match register_runtime_stack_callback(callback, runtime_type, callback_type) {
100+
match register_runtime_stack_callback(callback, callback_type) {
106101
Ok(()) => CallbackResult::Ok,
107102
Err(e) => e.into(),
108103
}
@@ -119,20 +114,6 @@ pub extern "C" fn ddog_crasht_is_runtime_callback_registered() -> bool {
119114
is_runtime_callback_registered()
120115
}
121116

122-
/// Get the runtime type from the currently registered callback context
123-
///
124-
/// Returns the runtime type C string pointer if a callback with valid context is registered,
125-
/// null pointer otherwise
126-
///
127-
/// # Safety
128-
/// - The returned pointer is valid only while the callback remains registered
129-
/// - The caller should not free the returned pointer
130-
/// - The returned string should be copied if it needs to persist beyond callback lifetime
131-
#[no_mangle]
132-
pub unsafe extern "C" fn ddog_crasht_get_registered_runtime_type() -> *const std::ffi::c_char {
133-
get_registered_runtime_type_ptr()
134-
}
135-
136117
/// Get the callback type from the currently registered callback context
137118
///
138119
/// Returns the callback type C string pointer if a callback with valid context is registered,
@@ -191,12 +172,10 @@ mod tests {
191172

192173
// Test that no callback is initially registered
193174
assert!(!ddog_crasht_is_runtime_callback_registered());
194-
assert_eq!(ddog_crasht_get_registered_runtime_type(), ptr::null());
195175

196176
// Test successful registration using type-safe enums
197177
let result = ddog_crasht_register_runtime_stack_callback(
198178
test_runtime_callback,
199-
RuntimeType::Ruby,
200179
CallbackType::Frame,
201180
);
202181

@@ -205,16 +184,9 @@ mod tests {
205184
// Verify callback is now registered
206185
assert!(ddog_crasht_is_runtime_callback_registered());
207186

208-
// Verify we can retrieve the runtime type
209-
let runtime_type_ptr = ddog_crasht_get_registered_runtime_type();
210-
assert!(!runtime_type_ptr.is_null());
211-
let runtime_type_str = std::ffi::CStr::from_ptr(runtime_type_ptr).to_str().unwrap();
212-
assert_eq!(runtime_type_str, "ruby");
213-
214187
// Test duplicate registration fails
215188
let result = ddog_crasht_register_runtime_stack_callback(
216189
test_runtime_callback,
217-
RuntimeType::Ruby,
218190
CallbackType::Frame,
219191
);
220192
assert_eq!(result, CallbackResult::Ok);
@@ -239,19 +211,12 @@ mod tests {
239211
// Test registration with enum values - Python + StacktraceString
240212
let result = ddog_crasht_register_runtime_stack_callback(
241213
test_runtime_callback,
242-
RuntimeType::Python,
243214
CallbackType::StacktraceString,
244215
);
245216

246217
assert_eq!(result, CallbackResult::Ok);
247218
assert!(ddog_crasht_is_runtime_callback_registered());
248219

249-
// Verify runtime type
250-
let runtime_type_ptr = ddog_crasht_get_registered_runtime_type();
251-
assert!(!runtime_type_ptr.is_null());
252-
let runtime_type_str = std::ffi::CStr::from_ptr(runtime_type_ptr).to_str().unwrap();
253-
assert_eq!(runtime_type_str, "python");
254-
255220
// Verify callback type
256221
let callback_type_ptr = ddog_crasht_get_registered_callback_type();
257222
assert!(!callback_type_ptr.is_null());
@@ -263,17 +228,11 @@ mod tests {
263228
// Test re-registration with different values - Ruby + Frame
264229
let result = ddog_crasht_register_runtime_stack_callback(
265230
test_runtime_callback,
266-
RuntimeType::Ruby,
267231
CallbackType::Frame,
268232
);
269233

270234
assert_eq!(result, CallbackResult::Ok);
271235

272-
// Verify new values
273-
let runtime_type_ptr = ddog_crasht_get_registered_runtime_type();
274-
let runtime_type_str = std::ffi::CStr::from_ptr(runtime_type_ptr).to_str().unwrap();
275-
assert_eq!(runtime_type_str, "ruby");
276-
277236
let callback_type_ptr = ddog_crasht_get_registered_callback_type();
278237
let callback_type_str = std::ffi::CStr::from_ptr(callback_type_ptr)
279238
.to_str()

datadog-crashtracker/src/collector/emitters.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -225,32 +225,21 @@ fn emit_ucontext(w: &mut impl Write, ucontext: *const ucontext_t) -> Result<(),
225225
/// must be signal safe.
226226
fn emit_runtime_stack(w: &mut impl Write) -> Result<(), EmitterError> {
227227
let callback_type = unsafe { get_registered_callback_type_enum() };
228-
let runtime_type = unsafe { get_registered_runtime_type_enum() };
229228

230229
let callback_type = match callback_type {
231230
Some(ct) => ct,
232231
None => return Ok(()), // No callback registered
233232
};
234233

235-
let runtime_type_str = runtime_type.map(|rt| rt.as_str()).unwrap_or("unknown");
236-
237234
match callback_type {
238-
CallbackType::Frame => emit_runtime_stack_by_frames(w, runtime_type_str),
239-
CallbackType::StacktraceString => {
240-
emit_runtime_stack_by_stacktrace_string(w, runtime_type_str)
241-
}
235+
CallbackType::Frame => emit_runtime_stack_by_frames(w),
236+
CallbackType::StacktraceString => emit_runtime_stack_by_stacktrace_string(w),
242237
}
243238
}
244239

245-
fn emit_runtime_stack_by_frames(
246-
w: &mut impl Write,
247-
runtime_type: &str,
248-
) -> Result<(), EmitterError> {
240+
fn emit_runtime_stack_by_frames(w: &mut impl Write) -> Result<(), EmitterError> {
249241
writeln!(w, "{DD_CRASHTRACK_BEGIN_RUNTIME_STACK_FRAME}")?;
250242

251-
// Emit runtime type as metadata
252-
writeln!(w, "{{\"runtime_type\": \"{runtime_type}\"}}")?;
253-
254243
// JSON array for frames
255244
write!(w, "[")?;
256245
unsafe { invoke_runtime_callback_with_writer(w)? };
@@ -262,15 +251,9 @@ fn emit_runtime_stack_by_frames(
262251
Ok(())
263252
}
264253

265-
fn emit_runtime_stack_by_stacktrace_string(
266-
w: &mut impl Write,
267-
runtime_type: &str,
268-
) -> Result<(), EmitterError> {
254+
fn emit_runtime_stack_by_stacktrace_string(w: &mut impl Write) -> Result<(), EmitterError> {
269255
writeln!(w, "{DD_CRASHTRACK_BEGIN_RUNTIME_STACK_STRING}")?;
270256

271-
// Emit runtime type as metadata
272-
writeln!(w, "{{\"runtime_type\": \"{runtime_type}\"}}")?;
273-
274257
// Emit the stacktrace string
275258
unsafe { invoke_runtime_callback_with_writer(w)? };
276259

0 commit comments

Comments
 (0)