From dc85f53b73c93e6814f8325554f7cc7afdac35a4 Mon Sep 17 00:00:00 2001 From: iamluc Date: Tue, 17 Sep 2024 11:43:41 +0200 Subject: [PATCH 1/5] Add ionCube to the list of incompatible extensions --- ext/excluded_modules.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ext/excluded_modules.c b/ext/excluded_modules.c index 0caaa3d227..d1428c3c54 100644 --- a/ext/excluded_modules.c +++ b/ext/excluded_modules.c @@ -8,6 +8,12 @@ #include bool ddtrace_is_excluded_module(zend_module_entry *module, char *error) { + if (strcmp("ionCube Loader", module->name) == 0) { + snprintf(error, DDTRACE_EXCLUDED_MODULES_ERROR_MAX_LEN, + "Found incompatible ionCube Loader extension; disabling conflicting functionality"); + return true; + } + if (strcmp("xdebug", module->name) == 0) { /* PHP 7.0 was only supported from Xdebug 2.4 through 2.7 @@ -55,11 +61,7 @@ void ddtrace_excluded_modules_startup() { char error[DDTRACE_EXCLUDED_MODULES_ERROR_MAX_LEN + 1]; if (module && module->name && module->version && ddtrace_is_excluded_module(module, error)) { ddtrace_has_excluded_module = true; - if (strcmp("xdebug", module->name) == 0) { - LOG(ERROR, error); - } else { - LOG(WARN, error); - } + LOG(ERROR, error); return; } } From 85f05f76f41ac64fe5f35086c407cfe495120d1f Mon Sep 17 00:00:00 2001 From: iamluc Date: Tue, 17 Sep 2024 14:31:06 +0200 Subject: [PATCH 2/5] Add 'datadog.inject_force' INI setting to ignore incompatible extensions --- ext/configuration.h | 1 + ext/excluded_modules.c | 25 ++++++++++++++----- tests/xdebug/2.7.2/self_disable_php_7.0.phpt | 3 ++- tests/xdebug/2.9.2/force_inject.phpt | 18 +++++++++++++ tests/xdebug/2.9.2/self_disable.phpt | 3 ++- .../2.9.2/startup_logging_diagnostics.phpt | 2 +- 6 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 tests/xdebug/2.9.2/force_inject.phpt diff --git a/ext/configuration.h b/ext/configuration.h index b9c531f611..891f2d4e8c 100644 --- a/ext/configuration.h +++ b/ext/configuration.h @@ -226,6 +226,7 @@ enum ddtrace_sampling_rules_format { CONFIG(INT, DD_OPENAI_SPAN_CHAR_LIMIT, "128") \ CONFIG(DOUBLE, DD_OPENAI_SPAN_PROMPT_COMPLETION_SAMPLE_RATE, "1.0") \ CONFIG(DOUBLE, DD_OPENAI_LOG_PROMPT_COMPLETION_SAMPLE_RATE, "0.1") \ + CONFIG(BOOL, DD_INJECT_FORCE, "false") \ DD_INTEGRATIONS #ifndef _WIN32 diff --git a/ext/excluded_modules.c b/ext/excluded_modules.c index d1428c3c54..2bdecab39a 100644 --- a/ext/excluded_modules.c +++ b/ext/excluded_modules.c @@ -6,11 +6,12 @@ #include #include +#include "configuration.h" bool ddtrace_is_excluded_module(zend_module_entry *module, char *error) { if (strcmp("ionCube Loader", module->name) == 0) { snprintf(error, DDTRACE_EXCLUDED_MODULES_ERROR_MAX_LEN, - "Found incompatible ionCube Loader extension; disabling conflicting functionality"); + "Found incompatible ionCube Loader extension"); return true; } @@ -21,7 +22,7 @@ bool ddtrace_is_excluded_module(zend_module_entry *module, char *error) { */ #if PHP_VERSION_ID < 70100 snprintf(error, DDTRACE_EXCLUDED_MODULES_ERROR_MAX_LEN, - "Found incompatible Xdebug version %s; disabling conflicting functionality", module->version); + "Found incompatible Xdebug version %s", module->version); return true; #endif /* @@ -43,8 +44,7 @@ bool ddtrace_is_excluded_module(zend_module_entry *module, char *error) { int compare = php_version_compare(module->version, "2.9.5"); if (compare == -1) { snprintf(error, DDTRACE_EXCLUDED_MODULES_ERROR_MAX_LEN, - "Found incompatible Xdebug version %s; ddtrace requires Xdebug 2.9.5 or greater; disabling " - "conflicting functionality", + "Found incompatible Xdebug version %s; ddtrace requires Xdebug 2.9.5 or greater", module->version); return true; } @@ -56,14 +56,27 @@ void ddtrace_excluded_modules_startup() { zend_module_entry *module; ddtrace_has_excluded_module = false; + bool inject_force = (IS_TRUE == Z_TYPE(zai_config_memoized_entries[DDTRACE_CONFIG_DD_INJECT_FORCE].decoded_value)); ZEND_HASH_FOREACH_PTR(&module_registry, module) { char error[DDTRACE_EXCLUDED_MODULES_ERROR_MAX_LEN + 1]; if (module && module->name && module->version && ddtrace_is_excluded_module(module, error)) { ddtrace_has_excluded_module = true; - LOG(ERROR, error); - return; + if (inject_force) { + LOG(WARN, error); + } else { + LOG(ERROR, error); + } } } ZEND_HASH_FOREACH_END(); + + if (ddtrace_has_excluded_module) { + if (inject_force) { + LOG(WARN, "Found incompatible extension(s); ignoring since 'datadog.inject_force' is enabled"); + ddtrace_has_excluded_module = false; + } else { + LOG(ERROR, "Found incompatible extension(s); disabling conflicting functionality"); + } + } } diff --git a/tests/xdebug/2.7.2/self_disable_php_7.0.phpt b/tests/xdebug/2.7.2/self_disable_php_7.0.phpt index ca2cae91ad..d8a32bbac1 100644 --- a/tests/xdebug/2.7.2/self_disable_php_7.0.phpt +++ b/tests/xdebug/2.7.2/self_disable_php_7.0.phpt @@ -11,5 +11,6 @@ if (!extension_loaded('Xdebug')) die('skip: Xdebug required'); echo 'Done.' . PHP_EOL; ?> --EXPECTF-- -[ddtrace] [error] Found incompatible Xdebug version %s; disabling conflicting functionality +[ddtrace] [error] Found incompatible Xdebug version %s +[ddtrace] [error] Found incompatible extension(s); disabling conflicting functionality Done. diff --git a/tests/xdebug/2.9.2/force_inject.phpt b/tests/xdebug/2.9.2/force_inject.phpt new file mode 100644 index 0000000000..b735f5fe22 --- /dev/null +++ b/tests/xdebug/2.9.2/force_inject.phpt @@ -0,0 +1,18 @@ +--TEST-- +The tracer will ignore incompatible extensions +--SKIPIF-- + +--INI-- +xdebug.remote_enable=1 +datadog.inject_force=1 +datadog.trace.log_level=warn +--FILE-- += 0) die('Xdebug < 2.9.5 required'); + +echo 'Done.' . PHP_EOL; +?> +--EXPECTF-- +[ddtrace] [warning] Found incompatible Xdebug version %s; ddtrace requires Xdebug 2.9.5 or greater +[ddtrace] [warning] Found incompatible extension(s); ignoring since 'datadog.inject_force' is enabled +Done. diff --git a/tests/xdebug/2.9.2/self_disable.phpt b/tests/xdebug/2.9.2/self_disable.phpt index b40eaaf1ad..a6fe0fae32 100644 --- a/tests/xdebug/2.9.2/self_disable.phpt +++ b/tests/xdebug/2.9.2/self_disable.phpt @@ -11,5 +11,6 @@ if (!extension_loaded('Xdebug') || version_compare(phpversion('Xdebug'), '2.9.5' echo 'Done.' . PHP_EOL; ?> --EXPECTF-- -[ddtrace] [error] Found incompatible Xdebug version %s; ddtrace requires Xdebug 2.9.5 or greater; disabling conflicting functionality +[ddtrace] [error] Found incompatible Xdebug version %s; ddtrace requires Xdebug 2.9.5 or greater +[ddtrace] [error] Found incompatible extension(s); disabling conflicting functionality Done. diff --git a/tests/xdebug/2.9.2/startup_logging_diagnostics.phpt b/tests/xdebug/2.9.2/startup_logging_diagnostics.phpt index 27599a5ff3..f639637a3e 100644 --- a/tests/xdebug/2.9.2/startup_logging_diagnostics.phpt +++ b/tests/xdebug/2.9.2/startup_logging_diagnostics.phpt @@ -18,4 +18,4 @@ if (!isset($logs['incompatible module xdebug'])) { echo 'Log: ' . $logs['incompatible module xdebug'] . PHP_EOL; ?> --EXPECT-- -Log: Found incompatible Xdebug version 2.9.2; ddtrace requires Xdebug 2.9.5 or greater; disabling conflicting functionality +Log: Found incompatible Xdebug version 2.9.2; ddtrace requires Xdebug 2.9.5 or greater From 6d54c56616fa5743689faa342b0c307d7a2332b6 Mon Sep 17 00:00:00 2001 From: iamluc Date: Tue, 17 Sep 2024 14:50:38 +0200 Subject: [PATCH 3/5] Conflict with ionCube only on PHP 8.0+ --- ext/excluded_modules.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/excluded_modules.c b/ext/excluded_modules.c index 2bdecab39a..839336f02a 100644 --- a/ext/excluded_modules.c +++ b/ext/excluded_modules.c @@ -9,11 +9,13 @@ #include "configuration.h" bool ddtrace_is_excluded_module(zend_module_entry *module, char *error) { +#if PHP_VERSION_ID >= 80000 if (strcmp("ionCube Loader", module->name) == 0) { snprintf(error, DDTRACE_EXCLUDED_MODULES_ERROR_MAX_LEN, "Found incompatible ionCube Loader extension"); return true; } +#endif if (strcmp("xdebug", module->name) == 0) { /* From dd25a41c9f9dff452638a8d3c903237313ad1537 Mon Sep 17 00:00:00 2001 From: Luc Vieillescazes Date: Tue, 17 Sep 2024 15:51:00 +0200 Subject: [PATCH 4/5] Fix access of global config Co-authored-by: Bob Weinand --- ext/excluded_modules.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/excluded_modules.c b/ext/excluded_modules.c index 839336f02a..4bad02a804 100644 --- a/ext/excluded_modules.c +++ b/ext/excluded_modules.c @@ -58,7 +58,7 @@ void ddtrace_excluded_modules_startup() { zend_module_entry *module; ddtrace_has_excluded_module = false; - bool inject_force = (IS_TRUE == Z_TYPE(zai_config_memoized_entries[DDTRACE_CONFIG_DD_INJECT_FORCE].decoded_value)); + bool inject_force = get_global_DD_INJECT_FORCE(); ZEND_HASH_FOREACH_PTR(&module_registry, module) { char error[DDTRACE_EXCLUDED_MODULES_ERROR_MAX_LEN + 1]; From 2581e73eb9a7dd15facbe3b2ee5b11db1c457891 Mon Sep 17 00:00:00 2001 From: Luc Vieillescazes Date: Thu, 19 Sep 2024 16:09:28 +0200 Subject: [PATCH 5/5] Fix ini_change mode Co-authored-by: Bob Weinand --- ext/configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/configuration.h b/ext/configuration.h index 891f2d4e8c..440d6c3f60 100644 --- a/ext/configuration.h +++ b/ext/configuration.h @@ -226,7 +226,7 @@ enum ddtrace_sampling_rules_format { CONFIG(INT, DD_OPENAI_SPAN_CHAR_LIMIT, "128") \ CONFIG(DOUBLE, DD_OPENAI_SPAN_PROMPT_COMPLETION_SAMPLE_RATE, "1.0") \ CONFIG(DOUBLE, DD_OPENAI_LOG_PROMPT_COMPLETION_SAMPLE_RATE, "0.1") \ - CONFIG(BOOL, DD_INJECT_FORCE, "false") \ + CONFIG(BOOL, DD_INJECT_FORCE, "false", .ini_change = zai_config_system_ini_change) \ DD_INTEGRATIONS #ifndef _WIN32