|
9 | 9 |
|
10 | 10 | #include "common.h" |
11 | 11 |
|
12 | | -/** |
13 | | - * A result type that includes debug/log messages along with the data |
14 | | - */ |
15 | | -typedef struct ddog_OkResult { |
16 | | - struct ddog_Vec_LibraryConfig value; |
17 | | - struct ddog_CString logs; |
18 | | -} ddog_OkResult; |
19 | | - |
20 | | -typedef enum ddog_LibraryConfigLoggedResult_Tag { |
21 | | - DDOG_LIBRARY_CONFIG_LOGGED_RESULT_OK, |
22 | | - DDOG_LIBRARY_CONFIG_LOGGED_RESULT_ERR, |
23 | | -} ddog_LibraryConfigLoggedResult_Tag; |
24 | | - |
25 | | -typedef struct ddog_LibraryConfigLoggedResult { |
26 | | - ddog_LibraryConfigLoggedResult_Tag tag; |
27 | | - union { |
28 | | - struct { |
29 | | - struct ddog_OkResult ok; |
30 | | - }; |
31 | | - struct { |
32 | | - struct ddog_Error err; |
33 | | - }; |
34 | | - }; |
35 | | -} ddog_LibraryConfigLoggedResult; |
36 | | - |
37 | 12 | #ifdef __cplusplus |
38 | 13 | extern "C" { |
39 | 14 | #endif // __cplusplus |
@@ -76,20 +51,60 @@ struct ddog_CStr ddog_library_config_local_stable_config_path(void); |
76 | 51 | void ddog_library_config_drop(struct ddog_LibraryConfigLoggedResult config_result); |
77 | 52 |
|
78 | 53 | /** |
79 | | - * Store tracer metadata to a file handle |
| 54 | + * Allocates and returns a pointer to a new `TracerMetadata` object on the heap. |
80 | 55 | * |
81 | 56 | * # Safety |
| 57 | + * This function returns a raw pointer. The caller is responsible for calling |
| 58 | + * `ddog_tracer_metadata_free` to deallocate the memory. |
| 59 | + * |
| 60 | + * # Returns |
| 61 | + * A non-null pointer to a newly allocated `TracerMetadata` instance. |
| 62 | + */ |
| 63 | +struct ddog_TracerMetadata *ddog_tracer_metadata_new(void); |
| 64 | + |
| 65 | +/** |
| 66 | + * Frees a `TracerMetadata` instance previously allocated with `ddog_tracer_metadata_new`. |
| 67 | + * |
| 68 | + * # Safety |
| 69 | + * - `ptr` must be a pointer previously returned by `ddog_tracer_metadata_new`. |
| 70 | + * - Double-freeing or passing an invalid pointer results in undefined behavior. |
| 71 | + * - Passing a null pointer is safe and does nothing. |
| 72 | + */ |
| 73 | +void ddog_tracer_metadata_free(struct ddog_TracerMetadata *ptr); |
| 74 | + |
| 75 | +/** |
| 76 | + * Sets a field of the `TracerMetadata` object pointed to by `ptr`. |
| 77 | + * |
| 78 | + * # Arguments |
| 79 | + * - `ptr`: Pointer to a `TracerMetadata` instance. |
| 80 | + * - `kind`: The metadata field to set (as defined in `MetadataKind`). |
| 81 | + * - `value`: A null-terminated C string representing the value to set. |
| 82 | + * |
| 83 | + * # Safety |
| 84 | + * - Both `ptr` and `value` must be non-null. |
| 85 | + * - `value` must point to a valid UTF-8 null-terminated string. |
| 86 | + * - If the string is not valid UTF-8, the function does nothing. |
| 87 | + */ |
| 88 | +void ddog_tracer_metadata_set(struct ddog_TracerMetadata *ptr, |
| 89 | + enum ddog_MetadataKind kind, |
| 90 | + const char *value); |
| 91 | + |
| 92 | +/** |
| 93 | + * Serializes the `TracerMetadata` into a platform-specific memory handle (e.g., memfd on Linux). |
| 94 | + * |
| 95 | + * # Safety |
| 96 | + * - `ptr` must be a valid, non-null pointer to a `TracerMetadata`. |
| 97 | + * |
| 98 | + * # Returns |
| 99 | + * - On Linux: a `TracerMemfdHandle` containing a raw file descriptor to a memory file. |
| 100 | + * - On unsupported platforms: an error. |
| 101 | + * - On failure: propagates any internal errors from the metadata storage process. |
82 | 102 | * |
83 | | - * Accepts raw C-compatible strings |
| 103 | + * # Platform Support |
| 104 | + * This function currently only supports Linux via `memfd`. On other platforms, |
| 105 | + * it will return an error. |
84 | 106 | */ |
85 | | -struct ddog_Result_TracerMemfdHandle ddog_store_tracer_metadata(uint8_t schema_version, |
86 | | - ddog_CharSlice runtime_id, |
87 | | - ddog_CharSlice tracer_language, |
88 | | - ddog_CharSlice tracer_version, |
89 | | - ddog_CharSlice hostname, |
90 | | - ddog_CharSlice service_name, |
91 | | - ddog_CharSlice service_env, |
92 | | - ddog_CharSlice service_version); |
| 107 | +struct ddog_Result_TracerMemfdHandle ddog_tracer_metadata_store(struct ddog_TracerMetadata *ptr); |
93 | 108 |
|
94 | 109 | #ifdef __cplusplus |
95 | 110 | } // extern "C" |
|
0 commit comments