Skip to content

Commit 2c440ab

Browse files
dubloombwoebicataphract
authored
Adds process tags to remote config payload (#3658)
* bump libdatadog * Adds process tags to remote config payload * now process tags are passed as a vec * fix appsec test * leiyks review * bump libdatadog * fix build * Fix build Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com> * Fix build Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com> * Fix permission issue in appsec int build.gradle * Pin new version of image nginx-fpm-php-8.5-release-musl --------- Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com> Co-authored-by: Bob Weinand <bob.weinand@datadoghq.com> Co-authored-by: Gustavo André dos Santos Lopes <gustavo.lopes@datadoghq.com>
1 parent bfbcb5b commit 2c440ab

27 files changed

Lines changed: 666 additions & 162 deletions

Cargo.lock

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

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ RUN_TESTS_CMD := DD_SERVICE= DD_ENV= REPORT_EXIT_STATUS=1 TEST_PHP_SRCDIR=$(PROJ
4848

4949
C_FILES = $(shell find components components-rs ext src/dogstatsd zend_abstract_interface -name '*.c' -o -name '*.h' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
5050
TEST_FILES = $(shell find tests/ext -name '*.php*' -o -name '*.inc' -o -name '*.json' -o -name '*.yaml' -o -name 'CONFLICTS' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
51-
RUST_FILES = $(BUILD_DIR)/Cargo.toml $(BUILD_DIR)/Cargo.lock $(shell find components-rs -name '*.c' -o -name '*.rs' -o -name 'Cargo.toml' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' ) $(shell find libdatadog/{build-common,datadog-ffe,datadog-ipc,datadog-ipc-macros,datadog-live-debugger,datadog-live-debugger-ffi,datadog-remote-config,datadog-sidecar,datadog-sidecar-ffi,datadog-sidecar-macros,libdd-alloc,libdd-common,libdd-common-ffi,libdd-crashtracker,libdd-crashtracker-ffi,libdd-data-pipeline,libdd-ddsketch,libdd-dogstatsd-client,libdd-library-config,libdd-library-config-ffi,libdd-log,libdd-telemetry,libdd-telemetry-ffi,libdd-tinybytes,libdd-trace-*,spawn_worker,tools/{cc_utils,sidecar_mockgen},libdd-trace-*,Cargo.toml} \( -type l -o -type f \) \( -path "*/src*" -o -path "*/examples*" -o -path "*Cargo.toml" -o -path "*/build.rs" -o -path "*/tests/dataservice.rs" -o -path "*/tests/service_functional.rs" \) -not -path "*/datadog-ipc/build.rs" -not -path "*/datadog-sidecar-ffi/build.rs")
51+
RUST_FILES = $(BUILD_DIR)/Cargo.toml $(BUILD_DIR)/Cargo.lock $(shell find components-rs -name '*.c' -o -name '*.rs' -o -name 'Cargo.toml' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' ) $(shell find libdatadog/{build-common,datadog-ffe,datadog-ipc,datadog-ipc-macros,datadog-live-debugger,datadog-live-debugger-ffi,datadog-remote-config,datadog-sidecar,datadog-sidecar-ffi,datadog-sidecar-macros,libdd-alloc,libdd-common,libdd-common-ffi,libdd-crashtracker,libdd-crashtracker-ffi,libdd-data-pipeline,libdd-ddsketch,libdd-dogstatsd-client,libdd-library-config,libdd-library-config-ffi,libdd-log,libdd-libunwind-sys,libdd-telemetry,libdd-telemetry-ffi,libdd-tinybytes,libdd-trace-*,spawn_worker,tools/{cc_utils,sidecar_mockgen},libdd-trace-*,Cargo.toml} \( -type l -o -type f \) \( -path "*/src*" -o -path "*/examples*" -o -path "*/libunwind*" -o -path "*Cargo.toml" -o -path "*/build.rs" -o -path "*/tests/dataservice.rs" -o -path "*/tests/service_functional.rs" \) -not -path "*/datadog-ipc/build.rs" -not -path "*/datadog-sidecar-ffi/build.rs")
5252
ALL_OBJECT_FILES = $(C_FILES) $(RUST_FILES) $(BUILD_DIR)/Makefile
5353
TEST_OPCACHE_FILES = $(shell find tests/opcache -name '*.php*' -o -name '.gitkeep' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
5454
TEST_STUB_FILES = $(shell find tests/ext -type d -name 'stubs' -exec find '{}' -type f \; | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
@@ -500,7 +500,9 @@ $(PACKAGES_BUILD_DIR)/datadog-setup.php: $(PACKAGES_BUILD_DIR)
500500
$(PACKAGES_BUILD_DIR)
501501

502502
build_pecl_package:
503-
echo $(subst $(BUILD_DIR)/,,$(C_FILES) $(RUST_FILES) $(TEST_FILES) $(TEST_STUB_FILES) $(M4_FILES) Cargo.lock) | tooling/bin/pecl-build
503+
$(file >.pecl-files,$(subst $(BUILD_DIR)/,,$(C_FILES) $(RUST_FILES) $(TEST_FILES) $(TEST_STUB_FILES) $(M4_FILES) Cargo.lock))
504+
tooling/bin/pecl-build < .pecl-files
505+
@rm -f .pecl-files
504506

505507
dbgsym.tar.gz: $(PACKAGES_BUILD_DIR)
506508
$(if $(DDTRACE_MAKE_PACKAGES_ASAN), , tar -zcf $(PACKAGES_BUILD_DIR)/dd-library-php-$(VERSION)_windows_debugsymbols.tar.gz ./extensions_x86_64_debugsymbols --owner=0 --group=0)

appsec/tests/integration/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ def buildRunInDockerTask = { Map options ->
189189
}
190190
if (options.get('needsBoostCache', true)) {
191191
if (project.hasProperty('localBoostCache')) {
192-
binds[project.getProperty('localBoostCache')] = '/root/.boost'
192+
binds[project.getProperty('localBoostCache')] = '/var/boost-cache'
193193
} else {
194194
volumes['php-appsec-boost-cache'] = [
195-
mountPoint: '/root/.boost',
195+
mountPoint: '/var/boost-cache',
196196
task: createVolumeTask('php-appsec-boost-cache'),
197197
]
198198
}
@@ -390,7 +390,7 @@ def buildAppSecTask = { String version, String variant, altBaseTag = null ->
390390
-DDD_APPSEC_ENABLE_PATCHELF_LIBC=ON \\
391391
-DGIT_COMMIT=${libddwafCommit()} \\
392392
-DDD_APPSEC_TESTING=ON \\
393-
-DBOOST_CACHE_PREFIX=/root/.boost /project/appsec
393+
-DBOOST_CACHE_PREFIX=/var/boost-cache /project/appsec
394394
make -j extension ddappsec-helper && \\
395395
touch ddappsec.so libddappsec-helper.so
396396
"""

appsec/tests/integration/gradle/tag_mappings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,5 @@ ext.tag_mappings = [
137137
'nginx-fpm-php-8.5-release-zts': 'sha256:527f2ba273685ff7e3f72a74076fd6d99cbc87d51fb3485fef4dc80a0cfddeee',
138138
'nginx-fpm-php-8.5-release': 'sha256:fc2eea1ed06dfcf8102bdbfb2596f9a32bbe6493ca83d53370e1438289caa6aa',
139139
'nginx-fpm-php-8.5-debug': 'sha256:915d0155897e4f42cf1867b93edbb928afcc1c5b3bd3eccdb2d56ac50510cd82',
140-
'nginx-fpm-php-8.5-release-musl': 'sha256:73857002765b217e1076adc04f9ebc88505b0fa77fc48e2ad3005594b2f39bc9',
140+
'nginx-fpm-php-8.5-release-musl': 'sha256:a1ef09c1bf398049b340ab2a1c40839d828420df5a404831bb7b33a09d433755',
141141
]

appsec/tests/integration/src/docker/nginx-fpm-musl/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ FROM php:8.5-fpm-alpine
33
# doubles as php/toolchain image for musl
44

55
RUN apk add --no-cache \
6-
autoconf bash bison clang clang-dev cmake curl curl-dev \
6+
autoconf automake bash bison clang clang-dev cmake curl curl-dev \
77
g++ gcc gdb git libc-dev linux-headers llvm-libunwind-static make \
8-
musl-dev nginx oniguruma-dev openssl-dev patchelf pkgconf re2c \
8+
musl-dev nginx oniguruma-dev openssl-dev patchelf pkgconf re2c libtool \
99
libxml2-dev libzip-dev xz-static zlib-dev \
1010
vim
1111

appsec/tests/integration/src/main/groovy/com/datadog/appsec/php/mock_agent/rem_cfg/RemoteConfigRequest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ public static class TracerInfo {
218218
@JsonProperty("app_version")
219219
public String serviceVersion;
220220

221+
@JsonProperty("process_tags")
222+
public List<String> processTags;
223+
224+
@JsonProperty("container_tags")
225+
public List<String> containerTags;
226+
221227
@Override
222228
public String toString() {
223229
return new StringJoiner(", ", TracerInfo.class.getSimpleName() + "[", "]")
@@ -229,6 +235,8 @@ public String toString() {
229235
.add("extraServices=" + extraServices)
230236
.add("serviceEnv='" + serviceEnv + "'")
231237
.add("serviceVersion='" + serviceVersion + "'")
238+
.add("processTags=" + processTags)
239+
.add("container_tags=" + containerTags)
232240
.toString();
233241
}
234242
}

cbindgen.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rename_types = "PascalCase"
2323
"PushTagResult" = "ddog_Vec_Tag_PushResult"
2424
"ZendString" = "_zend_string"
2525
"FILE" = "FILE"
26+
"EndpointConfig" = "ddog_crasht_EndpointConfig"
2627

2728
[enum]
2829
prefix_with_name = true

components-rs/common.h

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
# define DDOG_CHECK_RETURN
4040
#endif
4141

42+
#ifdef _WIN32
43+
#define LIBDD_DLLIMPORT __declspec(dllimport)
44+
#else
45+
#define LIBDD_DLLIMPORT
46+
#endif
47+
4248
/**
4349
* Default value for the timeout field in milliseconds.
4450
*/
@@ -1231,9 +1237,6 @@ typedef enum ddog_crasht_SignalNames {
12311237
* variable to allow downgrading the collector.
12321238
*/
12331239
typedef enum ddog_crasht_StacktraceCollection {
1234-
/**
1235-
* Stacktrace collection occurs in the
1236-
*/
12371240
DDOG_CRASHT_STACKTRACE_COLLECTION_DISABLED,
12381241
DDOG_CRASHT_STACKTRACE_COLLECTION_WITHOUT_SYMBOLS,
12391242
/**
@@ -1286,6 +1289,14 @@ typedef struct ddog_crasht_Slice_CharSlice {
12861289
uintptr_t len;
12871290
} ddog_crasht_Slice_CharSlice;
12881291

1292+
typedef struct ddog_crasht_EndpointConfig {
1293+
ddog_CharSlice url;
1294+
ddog_CharSlice api_key;
1295+
ddog_CharSlice test_token;
1296+
uint64_t timeout;
1297+
bool use_system_resolver;
1298+
} ddog_crasht_EndpointConfig;
1299+
12891300
typedef struct ddog_crasht_Slice_I32 {
12901301
/**
12911302
* Should be non-null and suitably aligned for the underlying type. It is
@@ -1308,7 +1319,7 @@ typedef struct ddog_crasht_Config {
13081319
* The endpoint to send the crash report to (can be a file://).
13091320
* If None, the crashtracker will infer the agent host from env variables.
13101321
*/
1311-
const struct ddog_Endpoint *endpoint;
1322+
struct ddog_crasht_EndpointConfig endpoint;
13121323
/**
13131324
* Optional filename for a unix domain socket if the receiver is used asynchonously
13141325
*/
@@ -1388,6 +1399,14 @@ typedef struct ddog_crasht_Slice_CInt {
13881399
uintptr_t len;
13891400
} ddog_crasht_Slice_CInt;
13901401

1402+
/**
1403+
* Represents an object that should only be referred to by its handle.
1404+
* Do not access its member for any reason, only use the C API functions on this struct.
1405+
*/
1406+
typedef struct ddog_crasht_Handle_StackTrace {
1407+
struct ddog_crasht_StackTrace *inner;
1408+
} ddog_crasht_Handle_StackTrace;
1409+
13911410
/**
13921411
* A generic result type for when an operation may fail,
13931412
* or may return <T> in case of success.
@@ -1493,14 +1512,6 @@ typedef struct ddog_crasht_Span {
14931512
ddog_CharSlice thread_name;
14941513
} ddog_crasht_Span;
14951514

1496-
/**
1497-
* Represents an object that should only be referred to by its handle.
1498-
* Do not access its member for any reason, only use the C API functions on this struct.
1499-
*/
1500-
typedef struct ddog_crasht_Handle_StackTrace {
1501-
struct ddog_crasht_StackTrace *inner;
1502-
} ddog_crasht_Handle_StackTrace;
1503-
15041515
typedef struct ddog_crasht_ThreadData {
15051516
bool crashed;
15061517
ddog_CharSlice name;
@@ -1875,6 +1886,13 @@ void ddog_endpoint_set_timeout(struct ddog_Endpoint *endpoint, uint64_t millis);
18751886

18761887
void ddog_endpoint_set_test_token(struct ddog_Endpoint *endpoint, ddog_CharSlice token);
18771888

1889+
/**
1890+
* Set whether to use the system DNS resolver when building the reqwest client.
1891+
* If false, the default in-process resolver is used.
1892+
*/
1893+
void ddog_endpoint_set_use_system_resolver(struct ddog_Endpoint *endpoint,
1894+
bool use_system_resolver);
1895+
18781896
void ddog_endpoint_drop(struct ddog_Endpoint*);
18791897

18801898
struct ddog_Option_U32 ddog_Option_U32_some(uint32_t v);

components-rs/crashtracker.h

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,45 @@ struct ddog_VoidResult ddog_crasht_init_without_receiver(struct ddog_crasht_Conf
131131
*/
132132
struct ddog_crasht_Slice_CInt ddog_crasht_default_signals(void);
133133

134+
/**
135+
* Report an unhandled exception as a crash event.
136+
*
137+
* This function sends a crash report for an unhandled exception detected
138+
* by the runtime. It is intended to be called when the process is in a
139+
* terminal state due to an unhandled exception.
140+
*
141+
* # Parameters
142+
* - `error_type`: Optional type/class of the exception (e.g. "NullPointerException"). Pass empty
143+
* CharSlice for unknown.
144+
* - `error_message`: Optional error message. Pass empty CharSlice for no message.
145+
* - `runtime_stack`: Stack trace from the runtime. Consumed by this call.
146+
*
147+
* If the crash-tracker has not been initialized, this function is a no-op.
148+
*
149+
* # Side effects
150+
* This function disables the signal-based crash handler before performing
151+
* any work. This means that if the process receives a fatal signal (SIGSEGV)
152+
* during or after this call, the crashtracker will not produce a
153+
* second crash report. The previous signal handler (if any) will still be
154+
* chained.
155+
*
156+
* # Failure mode
157+
* If a fatal signal occurs while this function is in progress, the calling
158+
* process is in an unrecoverable state; the crashtracker cannot report the
159+
* secondary fault and the caller's own signal handler (if any) will execute
160+
* in a potentially corrupted context. Callers should treat this function as a
161+
* terminal operation and exit shortly after it returns.
162+
*
163+
* # Safety
164+
* Crash-tracking functions are not reentrant.
165+
* No other crash-handler functions should be called concurrently.
166+
* The `runtime_stack` handle must be valid and will be consumed.
167+
*/
168+
DDOG_CHECK_RETURN
169+
struct ddog_VoidResult ddog_crasht_report_unhandled_exception(ddog_CharSlice error_type,
170+
ddog_CharSlice error_message,
171+
struct ddog_crasht_Handle_StackTrace *runtime_stack);
172+
134173
/**
135174
* Removes all existing additional tags
136175
* Expected to be used after a fork, to reset the additional tags on the child
@@ -661,7 +700,12 @@ struct ddog_VoidResult ddog_crasht_CrashInfoBuilder_with_thread_name(struct ddog
661700
* The `builder` can be null, but if non-null it must point to a Builder made by this module,
662701
* which has not previously been dropped.
663702
* All arguments must be valid.
664-
* This method requires that the builder has a UUID and metadata set
703+
* This method requires that the builder has `metadata` and `kind` set
704+
* Applications can add `message` or `sig_info` to the builder to provide additional context.
705+
* If set, the data will be used to derive the crash ping message in the order of
706+
* - an explicit message set with `with_message`
707+
* - sig_info set with `with_sig_info`
708+
* - kind set with `with_kind`
665709
*/
666710
DDOG_CHECK_RETURN
667711
struct ddog_VoidResult ddog_crasht_CrashInfoBuilder_upload_ping_to_endpoint(struct ddog_crasht_Handle_CrashInfoBuilder *builder,

components-rs/ddtrace.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ void ddtrace_drop_rust_string(char *input, uintptr_t len);
3939

4040
struct ddog_Endpoint *ddtrace_parse_agent_url(ddog_CharSlice url);
4141

42+
void ddtrace_endpoint_as_crashtracker_config(const struct ddog_Endpoint *endpoint,
43+
void (*callback)(ddog_crasht_EndpointConfig, void*),
44+
void *userdata);
45+
4246
ddog_Configurator *ddog_library_configurator_new_dummy(bool debug_logs, ddog_CharSlice language);
4347

4448
int posix_spawn_file_actions_addchdir_np(void *file_actions, const char *path);
@@ -80,7 +84,8 @@ bool ddog_remote_configs_service_env_change(struct ddog_RemoteConfigState *remot
8084
ddog_CharSlice service,
8185
ddog_CharSlice env,
8286
ddog_CharSlice version,
83-
const struct ddog_Vec_Tag *tags);
87+
const struct ddog_Vec_Tag *tags,
88+
const struct ddog_Vec_Tag *process_tags);
8489

8590
bool ddog_remote_config_alter_dynamic_config(struct ddog_RemoteConfigState *remote_config,
8691
ddog_CharSlice config,

0 commit comments

Comments
 (0)