Skip to content

Commit 262f8b8

Browse files
Merge pull request #4053 from DataDog/christophe-papazian/appsec-agentic-onboarding
APPSEC-69232 Report DD_APPSEC_AGENTIC_ONBOARDING in config telemetry
2 parents 2db5578 + 503d055 commit 262f8b8

5 files changed

Lines changed: 135 additions & 0 deletions

File tree

ext/configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum datadog_sidecar_connection_mode {
7070
CONFIG(BOOL, DD_TRACE_FORCE_FLUSH_ON_SIGINT, "false") /* true if pid == 1 || ppid == 1 */ \
7171
CONFIG(BOOL, DD_APPSEC_ENABLED, "false", .ini_change = zai_config_system_ini_change) \
7272
CONFIG(BOOL, DD_APPSEC_RASP_ENABLED , "true") \
73+
CONFIG(STRING, DD_APPSEC_AGENTIC_ONBOARDING, "") \
7374
CONFIG(INT, DD_TRACE_AGENT_TIMEOUT, DD_CFG_EXPSTR(DD_TRACE_AGENT_TIMEOUT_VAL), \
7475
.ini_change = zai_config_system_ini_change) \
7576
CONFIG(INT, DD_TRACE_AGENT_CONNECT_TIMEOUT, DD_CFG_EXPSTR(DD_TRACE_AGENT_CONNECT_TIMEOUT_VAL), \

metadata/supported-configurations.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
"default": "true"
3737
}
3838
],
39+
"DD_APPSEC_AGENTIC_ONBOARDING": [
40+
{
41+
"implementation": "A",
42+
"type": "string",
43+
"default": ""
44+
}
45+
],
3946
"DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING_ENABLED": [
4047
{
4148
"implementation": "A",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
DD_APPSEC_AGENTIC_ONBOARDING flag is sent via telemetry with default (empty) value
3+
--DESCRIPTION--
4+
RFC-1113: telemetry-only marker; always reported, empty with origin=default when unset
5+
--SKIPIF--
6+
<?php
7+
if (getenv('PHP_PEAR_RUNTESTS') === '1') die("skip: pecl run-tests does not support {PWD}");
8+
if (PHP_OS === "WINNT" && PHP_VERSION_ID < 70400) die("skip: Windows on PHP 7.2 and 7.3 have permission issues with synchronous access to telemetry");
9+
if (getenv('USE_ZEND_ALLOC') === '0' && !getenv("SKIP_ASAN")) die('skip timing sensitive test - valgrind is too slow');
10+
require __DIR__ . '/../includes/clear_skipif_telemetry.inc'
11+
?>
12+
--ENV--
13+
DD_TRACE_GENERATE_ROOT_SPAN=0
14+
DD_INSTRUMENTATION_TELEMETRY_ENABLED=1
15+
--INI--
16+
datadog.trace.agent_url="file://{PWD}/agentic_onboarding_is_sent_01-telemetry.out"
17+
--FILE_EXTERNAL--
18+
agentic_onboarding_test.inc
19+
--EXPECT--
20+
array(5) {
21+
["name"]=>
22+
string(28) "DD_APPSEC_AGENTIC_ONBOARDING"
23+
["value"]=>
24+
string(0) ""
25+
["origin"]=>
26+
string(7) "default"
27+
["config_id"]=>
28+
NULL
29+
["seq_id"]=>
30+
NULL
31+
}
32+
string(4) "Sent"
33+
--CLEAN--
34+
<?php
35+
36+
@unlink(__DIR__ . '/agentic_onboarding_is_sent_01-telemetry.out');
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
DD_APPSEC_AGENTIC_ONBOARDING flag is sent via telemetry with its raw value
3+
--DESCRIPTION--
4+
RFC-1113: telemetry-only marker; the raw string value is reported verbatim with origin=env_var
5+
--SKIPIF--
6+
<?php
7+
if (getenv('PHP_PEAR_RUNTESTS') === '1') die("skip: pecl run-tests does not support {PWD}");
8+
if (PHP_OS === "WINNT" && PHP_VERSION_ID < 70400) die("skip: Windows on PHP 7.2 and 7.3 have permission issues with synchronous access to telemetry");
9+
if (getenv('USE_ZEND_ALLOC') === '0' && !getenv("SKIP_ASAN")) die('skip timing sensitive test - valgrind is too slow');
10+
require __DIR__ . '/../includes/clear_skipif_telemetry.inc'
11+
?>
12+
--ENV--
13+
DD_TRACE_GENERATE_ROOT_SPAN=0
14+
DD_INSTRUMENTATION_TELEMETRY_ENABLED=1
15+
DD_APPSEC_AGENTIC_ONBOARDING=true
16+
--INI--
17+
datadog.trace.agent_url="file://{PWD}/agentic_onboarding_is_sent_02-telemetry.out"
18+
--FILE_EXTERNAL--
19+
agentic_onboarding_test.inc
20+
--EXPECT--
21+
array(5) {
22+
["name"]=>
23+
string(28) "DD_APPSEC_AGENTIC_ONBOARDING"
24+
["value"]=>
25+
string(4) "true"
26+
["origin"]=>
27+
string(7) "env_var"
28+
["config_id"]=>
29+
NULL
30+
["seq_id"]=>
31+
NULL
32+
}
33+
string(4) "Sent"
34+
--CLEAN--
35+
<?php
36+
37+
@unlink(__DIR__ . '/agentic_onboarding_is_sent_02-telemetry.out');
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
DDTrace\start_span();
3+
$root = DDTrace\root_span();
4+
5+
$id = basename(__FILE__, ".php");
6+
7+
$root->service = $id.'-telemetry-app';
8+
$root->meta['env'] = 'test-env';
9+
10+
DDTrace\close_span();
11+
12+
// At this stage, the service and env are stored to be used by telemetry
13+
dd_trace_serialize_closed_spans();
14+
15+
dd_trace_internal_fn("finalize_telemetry");
16+
17+
for ($i = 0; $i < 300; ++$i) {
18+
usleep(100000);
19+
if (file_exists(__DIR__ . '/'.$id.'-telemetry.out')) {
20+
$batches = [];
21+
foreach (file(__DIR__ . '/'.$id.'-telemetry.out') as $l) {
22+
if ($l) {
23+
$json = json_decode($l, true);
24+
if ($json) {
25+
if ($json["application"]["service_name"] == "background_sender-php-service" || $json["application"]["service_name"] == "datadog-ipc-helper") {
26+
continue;
27+
}
28+
array_push($batches, ...($json["request_type"] == "message-batch" ? $json["payload"] : [$json]));
29+
}
30+
}
31+
}
32+
$found = array_filter($batches, function ($json) {
33+
if ($json["request_type"] !== "app-client-configuration-change") {
34+
return false;
35+
}
36+
foreach($json["payload"]["configuration"] as $configuration) {
37+
if (stripos($configuration["name"], "agentic_onboarding") !== false) {
38+
var_dump($configuration);
39+
return true;
40+
}
41+
}
42+
return false;
43+
});
44+
if (count($found) == 1) {
45+
var_dump("Sent");
46+
break;
47+
}
48+
}
49+
}
50+
if ($i == 300) {
51+
var_dump(file(__DIR__ . '/'.$id.'-telemetry.out'));
52+
}
53+
54+
?>

0 commit comments

Comments
 (0)