@@ -129,13 +129,21 @@ TSRM_TLS void *TSRMLS_CACHE = NULL;
129129#endif
130130#endif
131131
132+ int ddtrace_disable = 0 ; // 0 = enabled, 1 = disabled via INI, 2 = disabled, but MINIT was fully executed
133+ static ZEND_INI_MH (dd_OnUpdateDisabled ) {
134+ UNUSED (entry , mh_arg1 , mh_arg2 , mh_arg3 , stage );
135+ if (!ddtrace_disable ) {
136+ ddtrace_disable = zend_ini_parse_bool (new_value );
137+ }
138+ return SUCCESS ;
139+ }
140+
132141PHP_INI_BEGIN ()
133- STD_PHP_INI_BOOLEAN ("ddtrace.disable" , "0" , PHP_INI_SYSTEM , OnUpdateBool , disable , zend_ddtrace_globals ,
134- ddtrace_globals )
142+ ZEND_INI_ENTRY ("ddtrace.disable" , "0" , PHP_INI_SYSTEM , dd_OnUpdateDisabled )
135143
136- // Exposed for testing only
137- STD_PHP_INI_ENTRY ("ddtrace.cgroup_file" , "/proc/self/cgroup" , PHP_INI_SYSTEM , OnUpdateString , cgroup_file ,
138- zend_ddtrace_globals , ddtrace_globals )
144+ // Exposed for testing only
145+ STD_PHP_INI_ENTRY ("ddtrace.cgroup_file" , "/proc/self/cgroup" , PHP_INI_SYSTEM , OnUpdateString , cgroup_file ,
146+ zend_ddtrace_globals , ddtrace_globals )
139147PHP_INI_END ()
140148
141149#if PHP_VERSION_ID >= 70300 && PHP_VERSION_ID < 70400
@@ -389,7 +397,7 @@ static void dd_activate_once(void) {
389397 ddtrace_generate_runtime_id ();
390398
391399 // must run before the first zai_hook_activate as ddtrace_telemetry_setup installs a global hook
392- if (!DDTRACE_G ( disable ) ) {
400+ if (!ddtrace_disable ) {
393401#ifndef _WIN32
394402 if (get_global_DD_INSTRUMENTATION_TELEMETRY_ENABLED () || get_global_DD_TRACE_SIDECAR_TRACE_SENDER ())
395403#endif
@@ -413,15 +421,15 @@ static void ddtrace_activate(void) {
413421 zend_hash_init (& DDTRACE_G (traced_spans ), 8 , unused , NULL , 0 );
414422 zend_hash_init (& DDTRACE_G (tracestate_unknown_dd_keys ), 8 , unused , NULL , 0 );
415423
416- if (!DDTRACE_G ( disable ) && ddtrace_has_excluded_module == true) {
417- DDTRACE_G ( disable ) = 2 ;
424+ if (!ddtrace_disable && ddtrace_has_excluded_module == true) {
425+ ddtrace_disable = 2 ;
418426 }
419427
420428 // ZAI config is always set up
421429 pthread_once (& dd_activate_once_control , dd_activate_once );
422430 zai_config_rinit ();
423431
424- if (!DDTRACE_G ( disable ) && (get_global_DD_INSTRUMENTATION_TELEMETRY_ENABLED () || get_global_DD_TRACE_SIDECAR_TRACE_SENDER ())) {
432+ if (!ddtrace_disable && (get_global_DD_INSTRUMENTATION_TELEMETRY_ENABLED () || get_global_DD_TRACE_SIDECAR_TRACE_SENDER ())) {
425433 ddtrace_sidecar_ensure_active ();
426434 }
427435
@@ -430,11 +438,11 @@ static void ddtrace_activate(void) {
430438 dd_save_sampling_rules_file_config (sampling_rules_file , PHP_INI_USER , PHP_INI_STAGE_RUNTIME );
431439 }
432440
433- if (!DDTRACE_G ( disable ) && strcmp (sapi_module .name , "cli" ) == 0 && !get_DD_TRACE_CLI_ENABLED ()) {
434- DDTRACE_G ( disable ) = 2 ;
441+ if (!ddtrace_disable && strcmp (sapi_module .name , "cli" ) == 0 && !get_DD_TRACE_CLI_ENABLED ()) {
442+ ddtrace_disable = 2 ;
435443 }
436444
437- if (DDTRACE_G ( disable ) ) {
445+ if (ddtrace_disable ) {
438446 ddtrace_disable_tracing_in_current_request ();
439447 }
440448
@@ -1002,7 +1010,7 @@ static void dd_disable_if_incompatible_sapi_detected(void) {
10021010 datadog_php_string_view module_name = datadog_php_string_view_from_cstr (sapi_module .name );
10031011 if (UNEXPECTED (!dd_is_compatible_sapi (module_name ))) {
10041012 LOG (WARN , "Incompatible SAPI detected '%s'; disabling ddtrace" , sapi_module .name );
1005- DDTRACE_G ( disable ) = 1 ;
1013+ ddtrace_disable = 1 ;
10061014 }
10071015}
10081016
@@ -1076,7 +1084,7 @@ static PHP_MINIT_FUNCTION(ddtrace) {
10761084 mod_ptr -> handle = NULL ;
10771085 /* }}} */
10781086
1079- if (DDTRACE_G ( disable ) ) {
1087+ if (ddtrace_disable ) {
10801088 return SUCCESS ;
10811089 }
10821090
@@ -1123,7 +1131,7 @@ static PHP_MSHUTDOWN_FUNCTION(ddtrace) {
11231131
11241132 UNREGISTER_INI_ENTRIES ();
11251133
1126- if (DDTRACE_G ( disable ) == 1 ) {
1134+ if (ddtrace_disable == 1 ) {
11271135 zai_config_mshutdown ();
11281136 zai_json_shutdown_bindings ();
11291137 return SUCCESS ;
@@ -1257,7 +1265,7 @@ static PHP_RINIT_FUNCTION(ddtrace) {
12571265 zai_interceptor_rinit ();
12581266#endif
12591267
1260- if (!DDTRACE_G ( disable ) ) {
1268+ if (!ddtrace_disable ) {
12611269 // With internal functions also being hookable, they must not be hooked before the CG(map_ptr_base) is zeroed
12621270 zai_hook_activate ();
12631271 DDTRACE_G (active_stack ) = ddtrace_init_root_span_stack ();
@@ -1376,11 +1384,11 @@ static PHP_RSHUTDOWN_FUNCTION(ddtrace) {
13761384
13771385 if (get_DD_TRACE_ENABLED ()) {
13781386 dd_force_shutdown_tracing ();
1379- } else if (!DDTRACE_G ( disable ) ) {
1387+ } else if (!ddtrace_disable ) {
13801388 dd_shutdown_hooks_and_observer ();
13811389 }
13821390
1383- if (!DDTRACE_G ( disable ) ) {
1391+ if (!ddtrace_disable ) {
13841392 OBJ_RELEASE (& DDTRACE_G (active_stack )-> std );
13851393 DDTRACE_G (active_stack ) = NULL ;
13861394 }
@@ -1427,7 +1435,7 @@ bool ddtrace_alter_dd_trace_disabled_config(zval *old_value, zval *new_value) {
14271435 return true;
14281436 }
14291437
1430- if (DDTRACE_G ( disable ) ) {
1438+ if (ddtrace_disable ) {
14311439 return Z_TYPE_P (new_value ) == IS_FALSE ; // no changing to enabled allowed if globally disabled
14321440 }
14331441
@@ -1437,7 +1445,7 @@ bool ddtrace_alter_dd_trace_disabled_config(zval *old_value, zval *new_value) {
14371445
14381446 if (Z_TYPE_P (old_value ) == IS_FALSE ) {
14391447 dd_initialize_request ();
1440- } else if (!DDTRACE_G ( disable ) ) { // if this is true, the request has not been initialized at all
1448+ } else if (!ddtrace_disable ) { // if this is true, the request has not been initialized at all
14411449 ddtrace_close_all_open_spans (false); // All remaining userland spans (and root span)
14421450 dd_clean_globals ();
14431451 }
@@ -1525,12 +1533,12 @@ static PHP_MINFO_FUNCTION(ddtrace) {
15251533 php_info_print_box_end ();
15261534
15271535 php_info_print_table_start ();
1528- php_info_print_table_row (2 , "Datadog tracing support" , DDTRACE_G ( disable ) ? "disabled" : "enabled" );
1536+ php_info_print_table_row (2 , "Datadog tracing support" , ddtrace_disable ? "disabled" : "enabled" );
15291537 php_info_print_table_row (2 , "Version" , PHP_DDTRACE_VERSION );
15301538 _dd_info_tracer_config ();
15311539 php_info_print_table_end ();
15321540
1533- if (!DDTRACE_G ( disable ) ) {
1541+ if (!ddtrace_disable ) {
15341542 _dd_info_diagnostics_table ();
15351543 }
15361544
@@ -1723,7 +1731,7 @@ PHP_FUNCTION(dd_trace_reset) {
17231731 LOG_LINE_ONCE (ERROR , "Unexpected parameters to dd_trace_reset" );
17241732 }
17251733
1726- if (DDTRACE_G ( disable ) ) {
1734+ if (ddtrace_disable ) {
17271735 RETURN_BOOL (0 );
17281736 }
17291737
0 commit comments