diff --git a/ext/sidecar.c b/ext/sidecar.c index 9732879acc..d39ef1e650 100644 --- a/ext/sidecar.c +++ b/ext/sidecar.c @@ -14,6 +14,7 @@ #include "telemetry.h" #include "serializer.h" #include "remote_config.h" +#include "process_tags.h" #ifndef _WIN32 #include "coms.h" #endif @@ -629,6 +630,11 @@ ddog_crasht_Metadata ddtrace_setup_crashtracking_metadata(ddog_Vec_Tag *tags) { const char *runtime_version = zend_get_module_version("Reflection"); ddtrace_sidecar_push_tag(tags, DDOG_CHARSLICE_C("runtime_version"), (ddog_CharSlice) {.ptr = (char *) runtime_version, .len = strlen(runtime_version)}); + zend_string *process_tags = ddtrace_process_tags_get_serialized(); + if (process_tags) { + ddtrace_sidecar_push_tag(tags, DDOG_CHARSLICE_C("process_tags"), (ddog_CharSlice) {.ptr = ZSTR_VAL(process_tags), .len = ZSTR_LEN(process_tags)}); + } + return (ddog_crasht_Metadata){ .library_name = DDOG_CHARSLICE_C_BARE("dd-trace-php"), .library_version = DDOG_CHARSLICE_C_BARE(PHP_DDTRACE_VERSION), diff --git a/tests/ext/crashtracker_process_tags.phpt b/tests/ext/crashtracker_process_tags.phpt new file mode 100644 index 0000000000..1bb4b2f904 --- /dev/null +++ b/tests/ext/crashtracker_process_tags.phpt @@ -0,0 +1,68 @@ +--TEST-- +[crasht] process tags are attached to crash report +--SKIPIF-- + +--ENV-- +DD_TRACE_LOG_LEVEL=0 +DD_AGENT_HOST=request-replayer +DD_TRACE_AGENT_PORT=80 +DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED=1 +--INI-- +datadog.trace.agent_test_session_token=tests/ext/crashtracker_process_tags.phpt +--FILE-- +replayRequest(); // cleanup possible leftover + +usleep(100000); // Let time to the sidecar to open the crashtracker socket + +posix_setrlimit(POSIX_RLIMIT_CORE, 0, 0); + +$php = getenv('TEST_PHP_EXECUTABLE'); +$args = getenv('TEST_PHP_ARGS')." ".getenv("TEST_PHP_EXTRA_ARGS"); +$cmd = $php." ".$args." -r 'posix_kill(posix_getpid(), 11);'"; +system($cmd); + +$rr->waitForRequest(function ($request) { + if ($request["uri"] != "/telemetry/proxy/api/v2/apmtelemetry") { + return false; + } + $body = json_decode($request["body"], true); + if ($body["request_type"] != "logs" || !isset($body["payload"][0]["message"])) { + return false; + } + + foreach ($body["payload"] as $payload) { + $payload["message"] = json_decode($payload["message"], true); + if (!isset($payload["message"]["metadata"])) { + break; + } + + $output = json_encode($payload, JSON_PRETTY_PRINT); + echo $output; + + return true; + } + + return false; +}); +?> +--EXPECTF-- +%A{ + "message": { +%A + "metadata": { + "library_name": "dd-trace-php", + "library_version": "%s", + "family": "php", + "tags": [%A + "process_tags:entrypoint.name:standard_input_code,entrypoint.type:script,entrypoint.workdir:%s,runtime.sapi:cli"%A +}%A