Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ext/sidecar.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "telemetry.h"
#include "serializer.h"
#include "remote_config.h"
#include "process_tags.h"
#ifndef _WIN32
#include "coms.h"
#endif
Expand Down Expand Up @@ -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),
Expand Down
68 changes: 68 additions & 0 deletions tests/ext/crashtracker_process_tags.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
--TEST--
[crasht] process tags are attached to crash report
--SKIPIF--
<?php
if (!extension_loaded('posix')) die('skip: posix extension required');
if (getenv('SKIP_ASAN') || getenv('USE_ZEND_ALLOC') === '0') die("skip: intentionally causes segfaults");
if (getenv('PHP_PEAR_RUNTESTS') === '1') die("skip: pecl run-tests does not support %A in EXPECTF");
if (getenv('DD_TRACE_CLI_ENABLED') === '0') die("skip: tracer is disabled");
include __DIR__ . '/includes/skipif_no_dev_env.inc';
?>
--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--
<?php

include __DIR__ . '/includes/request_replayer.inc';
$rr = new RequestReplayer();
$rr->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
Loading