Skip to content

Commit 6cee576

Browse files
bm1549claude
andauthored
Emit env var names in telemetry config (#3783)
* Emit env var names in telemetry config instead of INI-derived names Use the canonical environment variable name (e.g. DD_TRACE_GENERATE_ROOT_SPAN) directly from cfg->names[0] instead of stripping the "datadog." prefix from the PHP INI name (e.g. trace.generate_root_span). This is more correct as it uses the original source-of-truth name without any lossy round-trip transformation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Update appsec SCA telemetry tests for env var config names The SCA tests expected the old INI-derived name "appsec.sca_enabled" but the telemetry now emits the env var name "DD_APPSEC_SCA_ENABLED". Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Trigger CI on latest commit Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix case-sensitive search in SCA telemetry test helper The sca_test.inc helper uses strpos() to find "sca_enabled" in the config name, but the env var name DD_APPSEC_SCA_ENABLED is uppercase. Switch to stripos() for case-insensitive matching. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix string length in SCA test expectations (21, not 22) DD_APPSEC_SCA_ENABLED is 21 characters, not 22. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2b97a2a commit 6cee576

10 files changed

Lines changed: 28 additions & 29 deletions

ext/telemetry.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ void ddtrace_telemetry_finalize() {
158158
#if ZTS
159159
ini = zend_hash_find_ptr(EG(ini_directives), ini->name);
160160
#endif
161-
if (!zend_string_equals_literal(ini->name, "datadog.trace.enabled")) { // datadog.trace.enabled is meaningless: always off at rshutdown
161+
if (cfg->names[0].len != sizeof("DD_TRACE_ENABLED") - 1
162+
|| memcmp(cfg->names[0].ptr, "DD_TRACE_ENABLED", sizeof("DD_TRACE_ENABLED") - 1) != 0) { // DD_TRACE_ENABLED is meaningless: always off at rshutdown
162163
ddog_ConfigurationOrigin origin = DDOG_CONFIGURATION_ORIGIN_ENV_VAR;
163164
switch (cfg->name_index) {
164165
case ZAI_CONFIG_ORIGIN_DEFAULT:
@@ -176,9 +177,7 @@ void ddtrace_telemetry_finalize() {
176177
&& !zend_string_equals_cstr(ini->value, cfg->default_encoded_value.ptr, cfg->default_encoded_value.len)) {
177178
origin = cfg->name_index >= ZAI_CONFIG_ORIGIN_MODIFIED ? DDOG_CONFIGURATION_ORIGIN_ENV_VAR : DDOG_CONFIGURATION_ORIGIN_CODE;
178179
}
179-
ddog_CharSlice name = dd_zend_string_to_CharSlice(ini->name);
180-
name.len -= strlen("datadog.");
181-
name.ptr += strlen("datadog.");
180+
ddog_CharSlice name = (ddog_CharSlice){.ptr = cfg->names[0].ptr, .len = cfg->names[0].len};
182181
ddog_CharSlice config_id = (ddog_CharSlice) {.len = cfg->config_id.len, .ptr = cfg->config_id.ptr};
183182
ddog_sidecar_telemetry_enqueueConfig_buffer(buffer, name, dd_zend_string_to_CharSlice(ini->value), origin, config_id);
184183
}

tests/ext/appsec/sca_flag_is_sent_01.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ sca_test.inc
1919
--EXPECT--
2020
array(5) {
2121
["name"]=>
22-
string(18) "appsec.sca_enabled"
22+
string(21) "DD_APPSEC_SCA_ENABLED"
2323
["value"]=>
2424
string(5) "false"
2525
["origin"]=>

tests/ext/appsec/sca_flag_is_sent_02.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ sca_test.inc
2020
--EXPECT--
2121
array(5) {
2222
["name"]=>
23-
string(18) "appsec.sca_enabled"
23+
string(21) "DD_APPSEC_SCA_ENABLED"
2424
["value"]=>
2525
string(4) "true"
2626
["origin"]=>

tests/ext/appsec/sca_flag_is_sent_03.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ sca_test.inc
2020
--EXPECT--
2121
array(5) {
2222
["name"]=>
23-
string(18) "appsec.sca_enabled"
23+
string(21) "DD_APPSEC_SCA_ENABLED"
2424
["value"]=>
2525
string(5) "false"
2626
["origin"]=>

tests/ext/appsec/sca_flag_is_sent_04.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ sca_test.inc
2020
--EXPECT--
2121
array(5) {
2222
["name"]=>
23-
string(18) "appsec.sca_enabled"
23+
string(21) "DD_APPSEC_SCA_ENABLED"
2424
["value"]=>
2525
string(1) "1"
2626
["origin"]=>

tests/ext/appsec/sca_flag_is_sent_05.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ sca_test.inc
2020
--EXPECT--
2121
array(5) {
2222
["name"]=>
23-
string(18) "appsec.sca_enabled"
23+
string(21) "DD_APPSEC_SCA_ENABLED"
2424
["value"]=>
2525
string(1) "0"
2626
["origin"]=>

tests/ext/appsec/sca_test.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ for ($i = 0; $i < 300; ++$i) {
3434
return false;
3535
}
3636
foreach($json["payload"]["configuration"] as $configuration) {
37-
if (strpos($configuration["name"], "sca_enabled") !== false) {
37+
if (stripos($configuration["name"], "sca_enabled") !== false) {
3838
var_dump($configuration);
3939
return true;
4040
}

tests/ext/library_config/fleet_config.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ for ($i = 0; $i < 100; ++$i) {
5858
}
5959

6060
var_dump(array_values(array_filter($cfg, function ($c) {
61-
return in_array($c["name"], ['service', 'env', 'dynamic_instrumentation.enabled', 'trace.spans_limit', 'trace.generate_root_span']);
61+
return in_array($c["name"], ['DD_SERVICE', 'DD_ENV', 'DD_DYNAMIC_INSTRUMENTATION_ENABLED', 'DD_TRACE_SPANS_LIMIT', 'DD_TRACE_GENERATE_ROOT_SPAN']);
6262
})));
6363
break 3;
6464
}
@@ -81,7 +81,7 @@ array(5) {
8181
[0]=>
8282
array(5) {
8383
["name"]=>
84-
string(3) "env"
84+
string(6) "DD_ENV"
8585
["value"]=>
8686
string(21) "env_from_fleet_config"
8787
["origin"]=>
@@ -94,7 +94,7 @@ array(5) {
9494
[1]=>
9595
array(5) {
9696
["name"]=>
97-
string(7) "service"
97+
string(10) "DD_SERVICE"
9898
["value"]=>
9999
string(25) "service_from_fleet_config"
100100
["origin"]=>
@@ -107,7 +107,7 @@ array(5) {
107107
[2]=>
108108
array(5) {
109109
["name"]=>
110-
string(24) "trace.generate_root_span"
110+
string(27) "DD_TRACE_GENERATE_ROOT_SPAN"
111111
["value"]=>
112112
string(4) "true"
113113
["origin"]=>
@@ -120,7 +120,7 @@ array(5) {
120120
[3]=>
121121
array(5) {
122122
["name"]=>
123-
string(17) "trace.spans_limit"
123+
string(20) "DD_TRACE_SPANS_LIMIT"
124124
["value"]=>
125125
string(2) "42"
126126
["origin"]=>
@@ -133,7 +133,7 @@ array(5) {
133133
[4]=>
134134
array(5) {
135135
["name"]=>
136-
string(31) "dynamic_instrumentation.enabled"
136+
string(34) "DD_DYNAMIC_INSTRUMENTATION_ENABLED"
137137
["value"]=>
138138
string(4) "true"
139139
["origin"]=>

tests/ext/library_config/local_config.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ for ($i = 0; $i < 100; ++$i) {
5858
}
5959

6060
var_dump(array_values(array_filter($cfg, function ($c) {
61-
return in_array($c["name"], ['service', 'env', 'dynamic_instrumentation.enabled', 'trace.spans_limit', 'trace.generate_root_span']);
61+
return in_array($c["name"], ['DD_SERVICE', 'DD_ENV', 'DD_DYNAMIC_INSTRUMENTATION_ENABLED', 'DD_TRACE_SPANS_LIMIT', 'DD_TRACE_GENERATE_ROOT_SPAN']);
6262
})));
6363
break 3;
6464
}
@@ -81,7 +81,7 @@ array(5) {
8181
[0]=>
8282
array(5) {
8383
["name"]=>
84-
string(3) "env"
84+
string(6) "DD_ENV"
8585
["value"]=>
8686
string(21) "env_from_local_config"
8787
["origin"]=>
@@ -94,7 +94,7 @@ array(5) {
9494
[1]=>
9595
array(5) {
9696
["name"]=>
97-
string(7) "service"
97+
string(10) "DD_SERVICE"
9898
["value"]=>
9999
string(25) "service_from_local_config"
100100
["origin"]=>
@@ -107,7 +107,7 @@ array(5) {
107107
[2]=>
108108
array(5) {
109109
["name"]=>
110-
string(24) "trace.generate_root_span"
110+
string(27) "DD_TRACE_GENERATE_ROOT_SPAN"
111111
["value"]=>
112112
string(4) "true"
113113
["origin"]=>
@@ -120,7 +120,7 @@ array(5) {
120120
[3]=>
121121
array(5) {
122122
["name"]=>
123-
string(17) "trace.spans_limit"
123+
string(20) "DD_TRACE_SPANS_LIMIT"
124124
["value"]=>
125125
string(2) "42"
126126
["origin"]=>
@@ -133,7 +133,7 @@ array(5) {
133133
[4]=>
134134
array(5) {
135135
["name"]=>
136-
string(31) "dynamic_instrumentation.enabled"
136+
string(34) "DD_DYNAMIC_INSTRUMENTATION_ENABLED"
137137
["value"]=>
138138
string(4) "true"
139139
["origin"]=>

tests/ext/telemetry/config.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ for ($i = 0; $i < 300; ++$i) {
4848
if ($json["request_type"] == "app-client-configuration-change") {
4949
$cfg = $json["payload"]["configuration"];
5050
print_r(array_values(array_filter($cfg, function ($c) {
51-
return $c["origin"] == "env_var" && $c["name"] != "trace.sources_path" && $c["name"] != "trace.sidecar_trace_sender";
51+
return $c["origin"] == "env_var" && $c["name"] != "DD_TRACE_SOURCES_PATH" && $c["name"] != "DD_TRACE_SIDECAR_TRACE_SENDER";
5252
})));
5353
var_dump(count(array_filter($cfg, function ($c) {
5454
return $c["origin"] == "default";
@@ -74,7 +74,7 @@ Array
7474
(
7575
[0] => Array
7676
(
77-
[name] => trace.agent_url
77+
[name] => DD_TRACE_AGENT_URL
7878
[value] => file://%s/config-telemetry.out
7979
[origin] => env_var
8080
[config_id] =>
@@ -83,7 +83,7 @@ Array
8383

8484
[1] => Array
8585
(
86-
[name] => instrumentation_telemetry_enabled
86+
[name] => DD_INSTRUMENTATION_TELEMETRY_ENABLED
8787
[value] => 1
8888
[origin] => env_var
8989
[config_id] =>
@@ -92,7 +92,7 @@ Array
9292

9393
[2] => Array
9494
(
95-
[name] => trace.ignore_agent_sampling_rates
95+
[name] => DD_TRACE_IGNORE_AGENT_SAMPLING_RATES
9696
[value] => 1
9797
[origin] => env_var
9898
[config_id] =>
@@ -101,7 +101,7 @@ Array
101101

102102
[3] => Array
103103
(
104-
[name] => trace.generate_root_span
104+
[name] => DD_TRACE_GENERATE_ROOT_SPAN
105105
[value] => 0
106106
[origin] => env_var
107107
[config_id] =>
@@ -110,7 +110,7 @@ Array
110110

111111
[4] => Array
112112
(
113-
[name] => trace.git_metadata_enabled
113+
[name] => DD_TRACE_GIT_METADATA_ENABLED
114114
[value] => 0
115115
[origin] => env_var
116116
[config_id] =>
@@ -119,7 +119,7 @@ Array
119119

120120
[5] => Array
121121
(
122-
[name] => experimental_propagate_process_tags_enabled
122+
[name] => DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED
123123
[value] => 0
124124
[origin] => env_var
125125
[config_id] =>

0 commit comments

Comments
 (0)