@@ -11,7 +11,7 @@ use std::os::raw::{c_char, c_int};
1111/// C-compatible representation of an anonymous file handle
1212#[ repr( C ) ]
1313pub struct TracerMemfdHandle {
14- /// File descriptor (relevant only on Linux)
14+ /// File descriptor on Linux; `-1` on other platforms.
1515 pub fd : c_int ,
1616}
1717
@@ -102,21 +102,17 @@ pub unsafe extern "C" fn ddog_tracer_metadata_set(
102102 }
103103}
104104
105- /// Serializes the `TracerMetadata` into a platform-specific memory handle (e.g., memfd on Linux).
106- /// This function also attempts to publish the tracer metadata as an OTel process context
107- /// separately, but will ignore resulting errors .
105+ /// Stores the `TracerMetadata` using the platform's supported mechanisms. Linux serializes the
106+ /// metadata into a memfd and attempts to publish it as an OTel process context. Other platforms
107+ /// publish only the OTel process context .
108108///
109109/// # Safety
110110/// - `ptr` must be a valid, non-null pointer to a `TracerMetadata`.
111111///
112112/// # Returns
113113/// - On Linux: a `TracerMemfdHandle` containing a raw file descriptor to a memory file.
114- /// - On unsupported platforms: an error .
114+ /// - On other platforms: a `TracerMemfdHandle` with `fd` set to `-1` .
115115/// - On failure: propagates any internal errors from the metadata storage process.
116- ///
117- /// # Platform Support
118- /// This function currently only supports Linux via `memfd`. On other platforms,
119- /// it will return an error.
120116#[ no_mangle]
121117pub unsafe extern "C" fn ddog_tracer_metadata_store (
122118 ptr : * mut TracerMetadata ,
@@ -141,8 +137,23 @@ pub unsafe extern "C" fn ddog_tracer_metadata_store(
141137 } )
142138 }
143139 #[ cfg( not( target_os = "linux" ) ) ]
144- Ok ( _) => Err ( anyhow :: anyhow! ( "Unsupported platform" ) ) ,
140+ Ok ( _) => Ok ( TracerMemfdHandle { fd : - 1 } ) ,
145141 Err ( err) => Err ( err) ,
146142 } ;
147143 result. into ( )
148144}
145+
146+ #[ cfg( all( test, not( target_os = "linux" ) ) ) ]
147+ mod tests {
148+ use super :: { ddog_tracer_metadata_store, TracerMetadata } ;
149+
150+ #[ test]
151+ fn store_returns_success_without_a_file_descriptor ( ) {
152+ let mut metadata = TracerMetadata :: default ( ) ;
153+
154+ let handle = unsafe { ddog_tracer_metadata_store ( & mut metadata) } . unwrap ( ) ;
155+ assert_eq ! ( handle. fd, -1 ) ;
156+
157+ libdd_library_config:: otel_process_ctx:: unpublish ( ) . expect ( "unpublish should succeed" ) ;
158+ }
159+ }
0 commit comments