Skip to content

Commit 6bdf05a

Browse files
authored
Merge pull request #3415 from DataDog/glopes/http-endpoint
impl rfc "APM endpoint resource renaming in the tracers"
2 parents bc34608 + b8b8a90 commit 6bdf05a

20 files changed

+885
-1245
lines changed

Cargo.lock

Lines changed: 210 additions & 1191 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,18 @@ lto = true
2424
codegen-units = 1
2525
panic = "abort"
2626
inherits = "release"
27+
28+
# These are to satistfy the build with libdatadog as a path dependency inside
29+
# components-rs. There may be a better way to fix this, but I'm alreday two
30+
# tasks removed from what I'm trying to do, so pushing forward.
31+
[workspace.dependencies]
32+
hyper = { version = "1.6", features = [
33+
"http1",
34+
"client",
35+
], default-features = false }
36+
hyper-util = { version = "0.1.10", features = [
37+
"http1",
38+
"client",
39+
"client-legacy",
40+
] }
41+

components-rs/common.h

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,8 +1511,28 @@ typedef enum ddog_LibraryConfigSource {
15111511
DDOG_LIBRARY_CONFIG_SOURCE_FLEET_STABLE_CONFIG = 1,
15121512
} ddog_LibraryConfigSource;
15131513

1514+
/**
1515+
* Represents the types of metadata that can be set on a `TracerMetadata` object.
1516+
*/
1517+
typedef enum ddog_MetadataKind {
1518+
DDOG_METADATA_KIND_RUNTIME_ID = 0,
1519+
DDOG_METADATA_KIND_TRACER_LANGUAGE = 1,
1520+
DDOG_METADATA_KIND_TRACER_VERSION = 2,
1521+
DDOG_METADATA_KIND_HOSTNAME = 3,
1522+
DDOG_METADATA_KIND_SERVICE_NAME = 4,
1523+
DDOG_METADATA_KIND_SERVICE_ENV = 5,
1524+
DDOG_METADATA_KIND_SERVICE_VERSION = 6,
1525+
DDOG_METADATA_KIND_PROCESS_TAGS = 7,
1526+
DDOG_METADATA_KIND_CONTAINER_ID = 8,
1527+
} ddog_MetadataKind;
1528+
15141529
typedef struct ddog_Configurator ddog_Configurator;
15151530

1531+
/**
1532+
* This struct MUST be backward compatible.
1533+
*/
1534+
typedef struct ddog_TracerMetadata ddog_TracerMetadata;
1535+
15161536
/**
15171537
* Ffi safe type representing a borrowed null-terminated C array
15181538
* Equivalent to a std::ffi::CStr
@@ -1581,25 +1601,29 @@ typedef struct ddog_Vec_LibraryConfig {
15811601
} ddog_Vec_LibraryConfig;
15821602

15831603
/**
1584-
* A generic result type for when an operation may fail,
1585-
* or may return <T> in case of success.
1604+
* A result type that includes debug/log messages along with the data
15861605
*/
1587-
typedef enum ddog_Result_VecLibraryConfig_Tag {
1588-
DDOG_RESULT_VEC_LIBRARY_CONFIG_OK_VEC_LIBRARY_CONFIG,
1589-
DDOG_RESULT_VEC_LIBRARY_CONFIG_ERR_VEC_LIBRARY_CONFIG,
1590-
} ddog_Result_VecLibraryConfig_Tag;
1591-
1592-
typedef struct ddog_Result_VecLibraryConfig {
1593-
ddog_Result_VecLibraryConfig_Tag tag;
1606+
typedef struct ddog_OkResult {
1607+
struct ddog_Vec_LibraryConfig value;
1608+
struct ddog_CString logs;
1609+
} ddog_OkResult;
1610+
1611+
typedef enum ddog_LibraryConfigLoggedResult_Tag {
1612+
DDOG_LIBRARY_CONFIG_LOGGED_RESULT_OK,
1613+
DDOG_LIBRARY_CONFIG_LOGGED_RESULT_ERR,
1614+
} ddog_LibraryConfigLoggedResult_Tag;
1615+
1616+
typedef struct ddog_LibraryConfigLoggedResult {
1617+
ddog_LibraryConfigLoggedResult_Tag tag;
15941618
union {
15951619
struct {
1596-
struct ddog_Vec_LibraryConfig ok;
1620+
struct ddog_OkResult ok;
15971621
};
15981622
struct {
15991623
struct ddog_Error err;
16001624
};
16011625
};
1602-
} ddog_Result_VecLibraryConfig;
1626+
} ddog_LibraryConfigLoggedResult;
16031627

16041628
/**
16051629
* C-compatible representation of an anonymous file handle

components-rs/library-config.h

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void ddog_library_configurator_with_detect_process_info(struct ddog_Configurator
2828

2929
void ddog_library_configurator_drop(struct ddog_Configurator*);
3030

31-
struct ddog_Result_VecLibraryConfig ddog_library_configurator_get(const struct ddog_Configurator *configurator);
31+
struct ddog_LibraryConfigLoggedResult ddog_library_configurator_get(const struct ddog_Configurator *configurator);
3232

3333
/**
3434
* Returns a static null-terminated string, containing the name of the environment variable
@@ -48,23 +48,63 @@ struct ddog_CStr ddog_library_config_fleet_stable_config_path(void);
4848
*/
4949
struct ddog_CStr ddog_library_config_local_stable_config_path(void);
5050

51-
void ddog_library_config_drop(struct ddog_Vec_LibraryConfig);
51+
void ddog_library_config_drop(struct ddog_LibraryConfigLoggedResult config_result);
5252

5353
/**
54-
* Store tracer metadata to a file handle
54+
* Allocates and returns a pointer to a new `TracerMetadata` object on the heap.
5555
*
5656
* # Safety
57+
* This function returns a raw pointer. The caller is responsible for calling
58+
* `ddog_tracer_metadata_free` to deallocate the memory.
5759
*
58-
* Accepts raw C-compatible strings
60+
* # Returns
61+
* A non-null pointer to a newly allocated `TracerMetadata` instance.
5962
*/
60-
struct ddog_Result_TracerMemfdHandle ddog_store_tracer_metadata(uint8_t schema_version,
61-
ddog_CharSlice runtime_id,
62-
ddog_CharSlice tracer_language,
63-
ddog_CharSlice tracer_version,
64-
ddog_CharSlice hostname,
65-
ddog_CharSlice service_name,
66-
ddog_CharSlice service_env,
67-
ddog_CharSlice service_version);
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.
102+
*
103+
* # Platform Support
104+
* This function currently only supports Linux via `memfd`. On other platforms,
105+
* it will return an error.
106+
*/
107+
struct ddog_Result_TracerMemfdHandle ddog_tracer_metadata_store(struct ddog_TracerMetadata *ptr);
68108

69109
#ifdef __cplusplus
70110
} // extern "C"

config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ if test "$PHP_DDTRACE" != "no"; then
178178
ext/distributed_tracing_headers.c \
179179
ext/dogstatsd.c \
180180
ext/dogstatsd_client.c \
181+
ext/endpoint_guessing.c \
181182
ext/engine_api.c \
182183
ext/engine_hooks.c \
183184
ext/exception_serialize.c \

config.w32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if (PHP_DDTRACE != 'no') {
2929
DDTRACE_EXT_SOURCES += " distributed_tracing_headers.c";
3030
DDTRACE_EXT_SOURCES += " ddshared.c";
3131
DDTRACE_EXT_SOURCES += " dogstatsd.c";
32+
DDTRACE_EXT_SOURCES += " endpoint_guessing.c";
3233
DDTRACE_EXT_SOURCES += " engine_api.c";
3334
DDTRACE_EXT_SOURCES += " engine_hooks.c";
3435
DDTRACE_EXT_SOURCES += " exception_serialize.c";

ext/compatibility.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,20 @@ static inline void smart_str_append_printf(smart_str *dest, const char *format,
202202
zend_string_release(str);
203203
}
204204

205+
static inline size_t smart_str_get_len(smart_str *str) { return str->s ? ZSTR_LEN(str->s) : 0; }
206+
207+
static inline zend_string *smart_str_extract(smart_str *str) {
208+
if (str->s) {
209+
zend_string *res;
210+
smart_str_0(str);
211+
res = str->s;
212+
str->s = NULL;
213+
return res;
214+
} else {
215+
return ZSTR_EMPTY_ALLOC();
216+
}
217+
}
218+
205219
static inline zend_string *php_base64_encode_str(const zend_string *str) {
206220
return php_base64_encode((const unsigned char*)(ZSTR_VAL(str)), ZSTR_LEN(str));
207221
}

ext/configuration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ enum ddtrace_sampling_rules_format {
258258
CONFIG(SET, DD_TRACE_HTTP_SERVER_ERROR_STATUSES, "500-599", .ini_change = zai_config_system_ini_change) \
259259
CONFIG(BOOL, DD_CODE_ORIGIN_FOR_SPANS_ENABLED, "true") \
260260
CONFIG(INT, DD_CODE_ORIGIN_MAX_USER_FRAMES, "8") \
261+
CONFIG(BOOL, DD_TRACE_RESOURCE_RENAMING_ENABLED, "false") \
262+
CONFIG(BOOL, DD_TRACE_RESOURCE_RENAMING_ALWAYS_SIMPLIFIED_ENDPOINT, "false") \
261263
DD_INTEGRATIONS
262264

263265
#ifndef _WIN32

0 commit comments

Comments
 (0)