diff --git a/ext/configuration.c b/ext/configuration.c index 10a4fa0a5ec..f9b2d6c2bd0 100644 --- a/ext/configuration.c +++ b/ext/configuration.c @@ -145,6 +145,10 @@ static void dd_ini_env_to_ini_name(const zai_str env_name, zai_config_name *ini_ memcpy(ini_name->ptr, "datadog.", sizeof("datadog.") - 1); ini_name->len = env_name.len + DD_TO_DATADOG_INC; + if (env_name.ptr == strstr(env_name.ptr, "DD_APPSEC_")) { + ini_name->ptr[sizeof("datadog.appsec") - 1] = '.'; + } + if (env_name.ptr == strstr(env_name.ptr, "DD_TRACE_")) { ini_name->ptr[sizeof("datadog.trace") - 1] = '.'; } diff --git a/tests/ext/appsec/sca_flag_is_sent_01.phpt b/tests/ext/appsec/sca_flag_is_sent_01.phpt index 34fb481100a..028f483e5d5 100644 --- a/tests/ext/appsec/sca_flag_is_sent_01.phpt +++ b/tests/ext/appsec/sca_flag_is_sent_01.phpt @@ -11,57 +11,13 @@ if (getenv('USE_ZEND_ALLOC') === '0' && !getenv("SKIP_ASAN")) die('skip timing s DD_TRACE_GENERATE_ROOT_SPAN=0 DD_INSTRUMENTATION_TELEMETRY_ENABLED=1 --INI-- -datadog.trace.agent_url="file://{PWD}/simple-telemetry.out" ---FILE-- -service = 'simple-telemetry-app'; -$root->meta['env'] = 'test-env'; - -DDTrace\close_span(); - -// At this stage, the service and env are stored to be used by telemetry -dd_trace_serialize_closed_spans(); - -dd_trace_internal_fn("finalize_telemetry"); - -for ($i = 0; $i < 100; ++$i) { - usleep(100000); - if (file_exists(__DIR__ . '/simple-telemetry.out')) { - $batches = []; - foreach (file(__DIR__ . '/simple-telemetry.out') as $l) { - if ($l) { - $json = json_decode($l, true); - array_push($batches, ...($json["request_type"] == "message-batch" ? $json["payload"] : [$json])); - } - } - $found = array_filter($batches, function ($json) { - if ($json["request_type"] !== "app-started") { - return false; - } - foreach($json["payload"]["configuration"] as $configuration) { - if ($configuration["name"] == "appsec_sca_enabled") { - var_dump($configuration); - return true; - } - } - return false; - }); - if (count($found) == 1) { - var_dump("Sent"); - break; - } - } -} - -?> +datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_01-telemetry.out" +--FILE_EXTERNAL-- +sca_test.inc --EXPECT-- array(3) { ["name"]=> - string(18) "appsec_sca_enabled" + string(18) "appsec.sca_enabled" ["value"]=> string(5) "false" ["origin"]=> @@ -71,4 +27,4 @@ string(4) "Sent" --CLEAN-- service = 'simple-telemetry-app'; -$root->meta['env'] = 'test-env'; - -DDTrace\close_span(); - -// At this stage, the service and env are stored to be used by telemetry -dd_trace_serialize_closed_spans(); - -dd_trace_internal_fn("finalize_telemetry"); - -for ($i = 0; $i < 100; ++$i) { - usleep(100000); - if (file_exists(__DIR__ . '/simple-telemetry.out')) { - $batches = []; - foreach (file(__DIR__ . '/simple-telemetry.out') as $l) { - if ($l) { - $json = json_decode($l, true); - array_push($batches, ...($json["request_type"] == "message-batch" ? $json["payload"] : [$json])); - } - } - $found = array_filter($batches, function ($json) { - if ($json["request_type"] !== "app-started") { - return false; - } - foreach($json["payload"]["configuration"] as $configuration) { - if ($configuration["name"] == "appsec_sca_enabled") { - var_dump($configuration); - return true; - } - } - return false; - }); - if (count($found) == 1) { - var_dump("Sent"); - break; - } - } -} - -?> +datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_02-telemetry.out" +--FILE_EXTERNAL-- +sca_test.inc --EXPECT-- array(3) { ["name"]=> - string(18) "appsec_sca_enabled" + string(18) "appsec.sca_enabled" ["value"]=> string(4) "true" ["origin"]=> @@ -72,4 +28,4 @@ string(4) "Sent" --CLEAN-- service = 'simple-telemetry-app'; -$root->meta['env'] = 'test-env'; - -DDTrace\close_span(); - -// At this stage, the service and env are stored to be used by telemetry -dd_trace_serialize_closed_spans(); - -dd_trace_internal_fn("finalize_telemetry"); - -for ($i = 0; $i < 100; ++$i) { - usleep(100000); - if (file_exists(__DIR__ . '/simple-telemetry.out')) { - $batches = []; - foreach (file(__DIR__ . '/simple-telemetry.out') as $l) { - if ($l) { - $json = json_decode($l, true); - array_push($batches, ...($json["request_type"] == "message-batch" ? $json["payload"] : [$json])); - } - } - $found = array_filter($batches, function ($json) { - if ($json["request_type"] !== "app-started") { - return false; - } - foreach($json["payload"]["configuration"] as $configuration) { - if ($configuration["name"] == "appsec_sca_enabled") { - var_dump($configuration); - return true; - } - } - return false; - }); - if (count($found) == 1) { - var_dump("Sent"); - break; - } - } -} - -?> +datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_03-telemetry.out" +--FILE_EXTERNAL-- +sca_test.inc --EXPECT-- array(3) { ["name"]=> - string(18) "appsec_sca_enabled" + string(18) "appsec.sca_enabled" ["value"]=> string(5) "false" ["origin"]=> @@ -72,4 +28,4 @@ string(4) "Sent" --CLEAN-- +--ENV-- +DD_TRACE_GENERATE_ROOT_SPAN=0 +DD_INSTRUMENTATION_TELEMETRY_ENABLED=1 +--INI-- +datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_04-telemetry.out" +datadog.appsec.sca_enabled=1 +--FILE_EXTERNAL-- +sca_test.inc +--EXPECT-- +array(3) { + ["name"]=> + string(18) "appsec.sca_enabled" + ["value"]=> + string(1) "1" + ["origin"]=> + string(6) "EnvVar" +} +string(4) "Sent" +--CLEAN-- + +--ENV-- +DD_TRACE_GENERATE_ROOT_SPAN=0 +DD_INSTRUMENTATION_TELEMETRY_ENABLED=1 +--INI-- +datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_05-telemetry.out" +datadog.appsec.sca_enabled=0 +--FILE_EXTERNAL-- +sca_test.inc +--EXPECT-- +array(3) { + ["name"]=> + string(18) "appsec.sca_enabled" + ["value"]=> + string(1) "0" + ["origin"]=> + string(6) "EnvVar" +} +string(4) "Sent" +--CLEAN-- +service = $id.'-telemetry-app'; +$root->meta['env'] = 'test-env'; + +DDTrace\close_span(); + +// At this stage, the service and env are stored to be used by telemetry +dd_trace_serialize_closed_spans(); + +dd_trace_internal_fn("finalize_telemetry"); + +for ($i = 0; $i < 100; ++$i) { + usleep(100000); + if (file_exists(__DIR__ . '/'.$id.'-telemetry.out')) { + $batches = []; + foreach (file(__DIR__ . '/'.$id.'-telemetry.out') as $l) { + if ($l) { + $json = json_decode($l, true); + array_push($batches, ...($json["request_type"] == "message-batch" ? $json["payload"] : [$json])); + } + } + $found = array_filter($batches, function ($json) { + if ($json["request_type"] !== "app-started") { + return false; + } + foreach($json["payload"]["configuration"] as $configuration) { + if (str_contains($configuration["name"], "sca_enabled")) { + var_dump($configuration); + return true; + } + } + return false; + }); + if (count($found) == 1) { + var_dump("Sent"); + break; + } + } +} + +?> \ No newline at end of file