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
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
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
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
}
}
4 changes: 3 additions & 1 deletion tests/ext/live-debugger/exception-replay_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ require __DIR__ . "/live_debugger.inc";
reset_request_replayer();
?>
--EXPECTF--
array(5) {
array(6) {
["service"]=>
string(24) "exception-replay_002.php"
["ddsource"]=>
Expand Down Expand Up @@ -1029,4 +1029,6 @@ array(5) {
}
["message"]=>
NULL
["process_tags"]=>
NULL
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ reset_request_replayer();
?>
--EXPECTF--
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo %s
%Aarray(5) {
%Aarray(6) {
["service"]=>
string(47) "exception-replay_non_regression_2989_mysqli.php"
["ddsource"]=>
Expand Down Expand Up @@ -124,4 +124,6 @@ Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo %s
}
["message"]=>
NULL
["process_tags"]=>
NULL
}
Loading