|
7 | 7 | use function_name::named; |
8 | 8 | use libdd_common::tag::Tag; |
9 | 9 | use libdd_common_ffi::slice::{AsBytes, ByteSlice, CharSlice, Slice}; |
10 | | -use libdd_common_ffi::{wrap_with_ffi_result, Handle, Result, ToInner}; |
| 10 | +use libdd_common_ffi::{ |
| 11 | + wrap_with_ffi_result, wrap_with_void_ffi_result, Handle, Result, ToInner, VoidResult, |
| 12 | +}; |
11 | 13 | use libdd_profiling::exporter; |
12 | 14 | use libdd_profiling::exporter::ProfileExporter; |
13 | 15 | use libdd_profiling::internal::EncodedProfile; |
@@ -210,11 +212,41 @@ unsafe fn parse_json( |
210 | 212 | } |
211 | 213 | } |
212 | 214 |
|
| 215 | +/// Initializes the tokio runtime for the exporter. |
| 216 | +/// |
| 217 | +/// This function creates the tokio runtime used by `ddog_prof_Exporter_send_blocking`. |
| 218 | +/// It can be called ahead of time to ensure the runtime is ready before sending. |
| 219 | +/// |
| 220 | +/// # Thread Affinity |
| 221 | +/// |
| 222 | +/// **Important**: The runtime has thread affinity. This function should be called from |
| 223 | +/// the same thread that will later call `ddog_prof_Exporter_send_blocking`. |
| 224 | +/// |
| 225 | +/// # Arguments |
| 226 | +/// * `exporter` - Borrows the exporter. |
| 227 | +/// |
| 228 | +/// # Safety |
| 229 | +/// The `exporter` must point to a valid ProfileExporter that has not been dropped. |
| 230 | +#[no_mangle] |
| 231 | +#[must_use] |
| 232 | +#[named] |
| 233 | +pub unsafe extern "C" fn ddog_prof_Exporter_init_runtime( |
| 234 | + mut exporter: *mut Handle<ProfileExporter>, |
| 235 | +) -> VoidResult { |
| 236 | + wrap_with_void_ffi_result!({ |
| 237 | + let exporter = exporter.to_inner_mut()?; |
| 238 | + exporter.init_runtime()? |
| 239 | + }) |
| 240 | +} |
| 241 | + |
213 | 242 | /// Builds a request and sends it, returning the HttpStatus. |
214 | 243 | /// This is a more efficient version of calling `ddog_prof_Exporter_Request_build` |
215 | 244 | /// followed by `ddog_prof_Exporter_send`, as it avoids exposing the intermediate |
216 | 245 | /// `Request` object. |
217 | 246 | /// |
| 247 | +/// Note: If the runtime has not been initialized via `ddog_prof_Exporter_init_runtime`, |
| 248 | +/// it will be lazily initialized on first call. |
| 249 | +/// |
218 | 250 | /// # Arguments |
219 | 251 | /// * `exporter` - Borrows the exporter. |
220 | 252 | /// * `profile` - Takes ownership of the profile. |
|
0 commit comments