Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ generate_cbindgen: cbindgen_binary # Regenerate components-rs/ddtrace.h componen
mkdir -pv "$(BUILD_DIR)"; \
export CARGO_TARGET_DIR="$(BUILD_DIR)/target"; \
fi; \
cargo run -p tools -- $(PROJECT_ROOT)/components-rs/common.h $(PROJECT_ROOT)/components-rs/ddtrace.h $(PROJECT_ROOT)/components-rs/live-debugger.h $(PROJECT_ROOT)/components-rs/telemetry.h $(PROJECT_ROOT)/components-rs/sidecar.h $(PROJECT_ROOT)/components-rs/crashtracker.h $(PROJECT_ROOT)/components-rs/library-config.h \
cargo run -p tools --bin dedup_headers -- $(PROJECT_ROOT)/components-rs/common.h $(PROJECT_ROOT)/components-rs/ddtrace.h $(PROJECT_ROOT)/components-rs/live-debugger.h $(PROJECT_ROOT)/components-rs/telemetry.h $(PROJECT_ROOT)/components-rs/sidecar.h $(PROJECT_ROOT)/components-rs/crashtracker.h $(PROJECT_ROOT)/components-rs/library-config.h \
)

cbindgen_binary:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class TelemetryHelpers {
static names = ['logs']
List<Log> logs

Logs(Map m) {
this(m.logs as List)
}

Logs(List m) {
logs = m.collect { new Log(it as Map) }
}
Expand Down
4 changes: 4 additions & 0 deletions components-rs/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,10 @@ typedef struct ddog_crasht_OsInfo {

typedef struct ddog_crasht_ProcInfo {
uint32_t pid;
/**
* Optional crashing thread id; 0 means unset.
*/
uint32_t tid;
} ddog_crasht_ProcInfo;

typedef struct ddog_crasht_SigInfo {
Expand Down
10 changes: 10 additions & 0 deletions components-rs/crashtracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,16 @@ DDOG_CHECK_RETURN
struct ddog_VoidResult ddog_crasht_CrashInfoBuilder_with_message(struct ddog_crasht_Handle_CrashInfoBuilder *builder,
ddog_CharSlice message);

/**
* # Safety
* The `builder` can be null, but if non-null it must point to a Builder made by this module,
* which has not previously been dropped.
* The CharSlice must be valid.
*/
DDOG_CHECK_RETURN
struct ddog_VoidResult ddog_crasht_CrashInfoBuilder_with_thread_name(struct ddog_crasht_Handle_CrashInfoBuilder *builder,
ddog_CharSlice thread_name);

/**
* # Safety
* The `builder` can be null, but if non-null it must point to a Builder made by this module,
Expand Down
3 changes: 2 additions & 1 deletion components-rs/live-debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ struct ddog_DebuggerPayload *ddog_create_log_probe_snapshot(const struct ddog_Pr
const ddog_CharSlice *message,
ddog_CharSlice service,
ddog_CharSlice language,
uint64_t timestamp);
uint64_t timestamp,
ddog_CharSlice process_tags);

void ddog_update_payload_message(struct ddog_DebuggerPayload *payload, ddog_CharSlice message);

Expand Down
12 changes: 6 additions & 6 deletions components-rs/sidecar.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ ddog_MaybeError ddog_sidecar_enqueue_telemetry_point(ddog_CharSlice session_id_f
* Pointers must be valid, strings must be null-terminated if not null.
*/
ddog_MaybeError ddog_sidecar_enqueue_telemetry_metric(ddog_CharSlice session_id_ffi,
ddog_CharSlice runtime_id_ffi,
ddog_CharSlice service_name_ffi,
ddog_CharSlice env_name_ffi,
ddog_CharSlice metric_name_ffi,
enum ddog_MetricType metric_type,
enum ddog_MetricNamespace metric_namespace);
ddog_CharSlice runtime_id_ffi,
ddog_CharSlice service_name_ffi,
ddog_CharSlice env_name_ffi,
ddog_CharSlice metric_name_ffi,
enum ddog_MetricType metric_type,
enum ddog_MetricNamespace metric_namespace);

/**
* Sends a trace to the sidecar via shared memory.
Expand Down
9 changes: 8 additions & 1 deletion ext/live_debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "zend_hrtime.h"
#include "components-rs/common.h"
#include "zend_generators.h"
#include "process_tags.h"

ZEND_EXTERN_MODULE_GLOBALS(ddtrace);

Expand Down Expand Up @@ -391,7 +392,13 @@ static void dd_log_probe_ensure_payload(dd_log_probe_dyn *dyn, dd_log_probe_def
ddog_update_payload_message(dyn->payload, *msg);
} else {
dyn->service = ddtrace_active_service_name();
dyn->payload = ddog_create_log_probe_snapshot(&def->parent.probe, msg, dd_zend_string_to_CharSlice(dyn->service), DDOG_CHARSLICE_C("php"), ddtrace_nanoseconds_realtime() / 1000000);
dyn->payload = ddog_create_log_probe_snapshot(
&def->parent.probe,
msg,
dd_zend_string_to_CharSlice(dyn->service),
DDOG_CHARSLICE_C("php"),
ddtrace_nanoseconds_realtime() / 1000000,
dd_zend_string_to_CharSlice(ddtrace_process_tags_get_serialized()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion ext/process_tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static void serialize_process_tags(void) {
}

zend_string *ddtrace_process_tags_get_serialized(void) {
return (ddtrace_process_tags_enabled() && process_tags.serialized) ? process_tags.serialized : NULL;
return (ddtrace_process_tags_enabled() && process_tags.serialized) ? process_tags.serialized : ZSTR_EMPTY_ALLOC();
}

bool ddtrace_process_tags_enabled(void){
Expand Down
2 changes: 1 addition & 1 deletion ext/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ ddog_SpanBytes *ddtrace_serialize_span_to_rust_span(ddtrace_span_data *span, ddo

if (is_first_span) {
zend_string *process_tags = ddtrace_process_tags_get_serialized();
if (process_tags) {
if (ZSTR_LEN(process_tags)) {
ddog_add_str_span_meta_zstr(rust_span, "_dd.process_tags", process_tags);
}
}
Expand Down
2 changes: 1 addition & 1 deletion libdatadog
Submodule libdatadog updated 107 files
24 changes: 14 additions & 10 deletions tests/ext/crashtracker_jit_tags.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,24 @@ $rr->waitForRequest(function ($request) {
return false;
}
$body = json_decode($request["body"], true);
if ($body["request_type"] != "logs" || !isset($body["payload"][0]["message"])) {
return false;
}
$batch = $body["request_type"] == "message-batch" ? $body["payload"] : [$body];

foreach ($body["payload"] as $payload) {
$payload["message"] = json_decode($payload["message"], true);
if (!isset($payload["message"]["metadata"])) {
break;
foreach ($batch as $json) {
if ($json["request_type"] != "logs" || !isset($json["payload"]["logs"])) {
continue;
}

$output = json_encode($payload, JSON_PRETTY_PRINT);
echo $output;
foreach ($json["payload"]["logs"] as $payload) {
$payload["message"] = json_decode($payload["message"], true);
if (!isset($payload["message"]["metadata"])) {
break;
}

return true;
$output = json_encode($payload, JSON_PRETTY_PRINT);
echo $output;

return true;
}
}

return false;
Expand Down
28 changes: 16 additions & 12 deletions tests/ext/crashtracker_segfault.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,27 @@ $rr->waitForRequest(function ($request) {
return false;
}
$body = json_decode($request["body"], true);
if ($body["request_type"] != "logs" || !isset($body["payload"][0]["message"])) {
return false;
}
$batch = $body["request_type"] == "message-batch" ? $body["payload"] : [$body];

foreach ($body["payload"] as $payload) {
$payload["message"] = json_decode($payload["message"], true);
if (!isset($payload["message"]["metadata"])) {
break;
}
if (($payload["message"]["kind"] ?? "") == "Crash ping") {
foreach ($batch as $json) {
if ($json["request_type"] != "logs" || !isset($json["payload"]["logs"])) {
continue;
}

$output = json_encode($payload, JSON_PRETTY_PRINT);
echo $output;
foreach ($json["payload"]["logs"] as $payload) {
$payload["message"] = json_decode($payload["message"], true);
if (!isset($payload["message"]["metadata"])) {
break;
}
if (($payload["message"]["kind"] ?? "") == "Crash ping") {
continue;
}

$output = json_encode($payload, JSON_PRETTY_PRINT);
echo $output;

return true;
return true;
}
}

return false;
Expand Down
23 changes: 15 additions & 8 deletions tests/ext/crashtracker_segfault_disabled.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,24 @@ $rr->waitForRequest(function ($request) {
return false;
}
$body = json_decode($request["body"], true);
if ($body["request_type"] != "logs" || !isset($body["payload"][0]["message"])) {
return false;
}
$batch = $body["request_type"] == "message-batch" ? $body["payload"] : [$body];

foreach ($batch as $json) {
if ($json["request_type"] != "logs" || !isset($json["payload"]["logs"])) {
continue;
}

$payload = $body["payload"][0];
$payload["message"] = json_decode($payload["message"], true);
$output = json_encode($payload, JSON_PRETTY_PRINT);
foreach ($json["payload"]["logs"] as $payload) {
$payload["message"] = json_decode($payload["message"], true);
$output = json_encode($payload, JSON_PRETTY_PRINT);

echo $output;
echo $output;

return true;
}
}

return true;
return false;
});

?>
Expand Down
24 changes: 14 additions & 10 deletions tests/ext/crashtracker_segfault_windows.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,24 @@ $rr->waitForRequest(function ($request) {
return false;
}
$body = json_decode($request["body"], true);
if ($body["request_type"] != "logs" || !isset($body["payload"][0]["message"])) {
return false;
}
$batch = $body["request_type"] == "message-batch" ? $body["payload"] : [$body];

foreach ($body["payload"] as $payload) {
$payload["message"] = json_decode($payload["message"], true);
if (!isset($payload["message"]["metadata"])) {
break;
foreach ($batch as $json) {
if ($json["request_type"] != "logs" || !isset($json["payload"]["logs"])) {
continue;
}

$output = json_encode($payload, JSON_PRETTY_PRINT);
echo $output;
foreach ($json["payload"]["logs"] as $payload) {
$payload["message"] = json_decode($payload["message"], true);
if (!isset($payload["message"]["metadata"])) {
break;
}

return true;
$output = json_encode($payload, JSON_PRETTY_PRINT);
echo $output;

return true;
}
}

return false;
Expand Down
4 changes: 3 additions & 1 deletion tests/ext/live-debugger/debugger_log_probe.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ reset_request_replayer();
?>
--EXPECTF--
int(30)
array(5) {
array(6) {
["service"]=>
string(22) "debugger_log_probe.php"
["ddsource"]=>
Expand Down Expand Up @@ -247,4 +247,6 @@ array(5) {
[true]
[true]
"
["process_tags"]=>
NULL
}
61 changes: 61 additions & 0 deletions tests/ext/live-debugger/debugger_log_probe_process_tags.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
--TEST--
Live debugger log probe includes process_tags
--SKIPIF--
<?php include __DIR__ . '/../includes/skipif_no_dev_env.inc'; ?>
--ENV--
DD_AGENT_HOST=request-replayer
DD_TRACE_AGENT_PORT=80
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_DYNAMIC_INSTRUMENTATION_ENABLED=1
DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS=0.01
DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED=1
--INI--
datadog.trace.agent_test_session_token=live-debugger/log_probe_process_tags
--FILE--
<?php

require __DIR__ . "/live_debugger.inc";

reset_request_replayer();

function simple_function() {
return "hello";
}

await_probe_installation(function() {
build_log_probe([
"where" => ["methodName" => "simple_function"],
"captureSnapshot" => true,
"segments" => [
["str" => "Simple message"],
],
]);

\DDTrace\start_span(); // submit span data
});

simple_function();

$dlr = new DebuggerLogReplayer;
$log = $dlr->waitForDebuggerDataAndReplay();
$payload = json_decode($log["body"], true)[0];

if (isset($payload["process_tags"])) {
echo "Process tags found in payload\n";
$processTags = $payload["process_tags"];

var_dump($processTags);
} else {
echo "ERROR: process_tags not found in payload\n";
}

?>
--CLEAN--
<?php
require __DIR__ . "/live_debugger.inc";
reset_request_replayer();
?>
--EXPECTF--
Process tags found in payload
string(%d) "entrypoint.basedir:live-debugger,entrypoint.name:debugger_log_probe_process_tags,entrypoint.type:script,entrypoint.workdir:%s,runtime.sapi:cli"

Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ array(2) {
string(%d) "/debugger/v1/input?ddtags=debugger_version:1.%s,env:none,version:,runtime_id:%s-%s-%s-%s-%s,host_name:%s"
array(1) {
[0]=>
array(5) {
array(6) {
["service"]=>
string(34) "debugger_span_decoration_probe.php"
["ddsource"]=>
Expand Down Expand Up @@ -142,5 +142,7 @@ array(1) {
}
["message"]=>
string(32) "Evaluation errors for probe id 2"
["process_tags"]=>
NULL
}
}
8 changes: 6 additions & 2 deletions tests/ext/live-debugger/exception-replay_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ reset_request_replayer();
--EXPECTF--
array(2) {
[0]=>
array(5) {
array(6) {
["service"]=>
string(24) "exception-replay_001.php"
["ddsource"]=>
Expand Down Expand Up @@ -126,9 +126,11 @@ array(2) {
}
["message"]=>
NULL
["process_tags"]=>
NULL
}
[1]=>
array(5) {
array(6) {
["service"]=>
string(24) "exception-replay_001.php"
["ddsource"]=>
Expand Down Expand Up @@ -231,5 +233,7 @@ array(2) {
}
["message"]=>
NULL
["process_tags"]=>
NULL
}
}
Loading
Loading