@@ -129,13 +129,21 @@ TSRM_TLS void *TSRMLS_CACHE = NULL;
129
129
#endif
130
130
#endif
131
131
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
+
132
141
PHP_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 )
135
143
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 )
139
147
PHP_INI_END ()
140
148
141
149
#if PHP_VERSION_ID >= 70300 && PHP_VERSION_ID < 70400
@@ -389,7 +397,7 @@ static void dd_activate_once(void) {
389
397
ddtrace_generate_runtime_id ();
390
398
391
399
// 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 ) {
393
401
#ifndef _WIN32
394
402
if (get_global_DD_INSTRUMENTATION_TELEMETRY_ENABLED () || get_global_DD_TRACE_SIDECAR_TRACE_SENDER ())
395
403
#endif
@@ -413,15 +421,15 @@ static void ddtrace_activate(void) {
413
421
zend_hash_init (& DDTRACE_G (traced_spans ), 8 , unused , NULL , 0 );
414
422
zend_hash_init (& DDTRACE_G (tracestate_unknown_dd_keys ), 8 , unused , NULL , 0 );
415
423
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 ;
418
426
}
419
427
420
428
// ZAI config is always set up
421
429
pthread_once (& dd_activate_once_control , dd_activate_once );
422
430
zai_config_rinit ();
423
431
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 ())) {
425
433
ddtrace_sidecar_ensure_active ();
426
434
}
427
435
@@ -430,11 +438,11 @@ static void ddtrace_activate(void) {
430
438
dd_save_sampling_rules_file_config (sampling_rules_file , PHP_INI_USER , PHP_INI_STAGE_RUNTIME );
431
439
}
432
440
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 ;
435
443
}
436
444
437
- if (DDTRACE_G ( disable ) ) {
445
+ if (ddtrace_disable ) {
438
446
ddtrace_disable_tracing_in_current_request ();
439
447
}
440
448
@@ -1002,7 +1010,7 @@ static void dd_disable_if_incompatible_sapi_detected(void) {
1002
1010
datadog_php_string_view module_name = datadog_php_string_view_from_cstr (sapi_module .name );
1003
1011
if (UNEXPECTED (!dd_is_compatible_sapi (module_name ))) {
1004
1012
LOG (WARN , "Incompatible SAPI detected '%s'; disabling ddtrace" , sapi_module .name );
1005
- DDTRACE_G ( disable ) = 1 ;
1013
+ ddtrace_disable = 1 ;
1006
1014
}
1007
1015
}
1008
1016
@@ -1076,7 +1084,7 @@ static PHP_MINIT_FUNCTION(ddtrace) {
1076
1084
mod_ptr -> handle = NULL ;
1077
1085
/* }}} */
1078
1086
1079
- if (DDTRACE_G ( disable ) ) {
1087
+ if (ddtrace_disable ) {
1080
1088
return SUCCESS ;
1081
1089
}
1082
1090
@@ -1123,7 +1131,7 @@ static PHP_MSHUTDOWN_FUNCTION(ddtrace) {
1123
1131
1124
1132
UNREGISTER_INI_ENTRIES ();
1125
1133
1126
- if (DDTRACE_G ( disable ) == 1 ) {
1134
+ if (ddtrace_disable == 1 ) {
1127
1135
zai_config_mshutdown ();
1128
1136
zai_json_shutdown_bindings ();
1129
1137
return SUCCESS ;
@@ -1257,7 +1265,7 @@ static PHP_RINIT_FUNCTION(ddtrace) {
1257
1265
zai_interceptor_rinit ();
1258
1266
#endif
1259
1267
1260
- if (!DDTRACE_G ( disable ) ) {
1268
+ if (!ddtrace_disable ) {
1261
1269
// With internal functions also being hookable, they must not be hooked before the CG(map_ptr_base) is zeroed
1262
1270
zai_hook_activate ();
1263
1271
DDTRACE_G (active_stack ) = ddtrace_init_root_span_stack ();
@@ -1376,11 +1384,11 @@ static PHP_RSHUTDOWN_FUNCTION(ddtrace) {
1376
1384
1377
1385
if (get_DD_TRACE_ENABLED ()) {
1378
1386
dd_force_shutdown_tracing ();
1379
- } else if (!DDTRACE_G ( disable ) ) {
1387
+ } else if (!ddtrace_disable ) {
1380
1388
dd_shutdown_hooks_and_observer ();
1381
1389
}
1382
1390
1383
- if (!DDTRACE_G ( disable ) ) {
1391
+ if (!ddtrace_disable ) {
1384
1392
OBJ_RELEASE (& DDTRACE_G (active_stack )-> std );
1385
1393
DDTRACE_G (active_stack ) = NULL ;
1386
1394
}
@@ -1427,7 +1435,7 @@ bool ddtrace_alter_dd_trace_disabled_config(zval *old_value, zval *new_value) {
1427
1435
return true;
1428
1436
}
1429
1437
1430
- if (DDTRACE_G ( disable ) ) {
1438
+ if (ddtrace_disable ) {
1431
1439
return Z_TYPE_P (new_value ) == IS_FALSE ; // no changing to enabled allowed if globally disabled
1432
1440
}
1433
1441
@@ -1437,7 +1445,7 @@ bool ddtrace_alter_dd_trace_disabled_config(zval *old_value, zval *new_value) {
1437
1445
1438
1446
if (Z_TYPE_P (old_value ) == IS_FALSE ) {
1439
1447
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
1441
1449
ddtrace_close_all_open_spans (false); // All remaining userland spans (and root span)
1442
1450
dd_clean_globals ();
1443
1451
}
@@ -1525,12 +1533,12 @@ static PHP_MINFO_FUNCTION(ddtrace) {
1525
1533
php_info_print_box_end ();
1526
1534
1527
1535
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" );
1529
1537
php_info_print_table_row (2 , "Version" , PHP_DDTRACE_VERSION );
1530
1538
_dd_info_tracer_config ();
1531
1539
php_info_print_table_end ();
1532
1540
1533
- if (!DDTRACE_G ( disable ) ) {
1541
+ if (!ddtrace_disable ) {
1534
1542
_dd_info_diagnostics_table ();
1535
1543
}
1536
1544
@@ -1723,7 +1731,7 @@ PHP_FUNCTION(dd_trace_reset) {
1723
1731
LOG_LINE_ONCE (ERROR , "Unexpected parameters to dd_trace_reset" );
1724
1732
}
1725
1733
1726
- if (DDTRACE_G ( disable ) ) {
1734
+ if (ddtrace_disable ) {
1727
1735
RETURN_BOOL (0 );
1728
1736
}
1729
1737
0 commit comments