From d04bc8837db27242386adadb8fc03e42dbedfd3b Mon Sep 17 00:00:00 2001 From: Pawel Filipczak Date: Fri, 10 Jan 2025 11:26:02 +0100 Subject: [PATCH] Added warning log for Xdebug incompatibility (#1256) (#1257) --- agent/native/ext/lifecycle.cpp | 17 ++++++++++++----- .../native/libcommon/code/PhpBridgeInterface.h | 2 +- agent/native/libphpbridge/code/Debugging.cpp | 6 +++++- agent/native/libphpbridge/code/PhpBridge.h | 1 + docs/setup.asciidoc | 5 +++++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/agent/native/ext/lifecycle.cpp b/agent/native/ext/lifecycle.cpp index 6b4bc7bda..e4fb860b8 100644 --- a/agent/native/ext/lifecycle.cpp +++ b/agent/native/ext/lifecycle.cpp @@ -414,12 +414,19 @@ void elasticApmRequestInit() enableAccessToServerGlobal(); bool preloadDetected = requestCounter == 1 ? detectOpcachePreload() : false; - if (config && config->debugDiagnosticsFile && !preloadDetected && requestCounter <= 2) { + if (!preloadDetected && requestCounter <= 2) { if (ELASTICAPM_G(globals)->sharedMemory_->shouldExecuteOneTimeTaskAmongWorkers()) { - try { - elasticapm::utils::storeDiagnosticInformation(elasticapm::utils::getParameterizedString(config->debugDiagnosticsFile), *(ELASTICAPM_G(globals)->bridge_)); - } catch (std::exception const &e) { - ELASTIC_APM_LOG_WARNING( "Unable to write agent diagnostics: %s", e.what() ); + using namespace std::string_view_literals; + if ( ELASTICAPM_G( globals )->bridge_->isExtensionLoaded( "xdebug"sv ) ) { + ELASTIC_APM_LOG_WARNING( "Xdebug is loaded, which is not supported by the Elastic APM Agent. This may lead to stability or memory issues"); + } + + if (config && config->debugDiagnosticsFile) { + try { + elasticapm::utils::storeDiagnosticInformation(elasticapm::utils::getParameterizedString(config->debugDiagnosticsFile), *(ELASTICAPM_G(globals)->bridge_)); + } catch (std::exception const &e) { + ELASTIC_APM_LOG_WARNING( "Unable to write agent diagnostics: %s", e.what() ); + } } } } diff --git a/agent/native/libcommon/code/PhpBridgeInterface.h b/agent/native/libcommon/code/PhpBridgeInterface.h index fc74e4404..e4ccaf93b 100644 --- a/agent/native/libcommon/code/PhpBridgeInterface.h +++ b/agent/native/libcommon/code/PhpBridgeInterface.h @@ -22,7 +22,7 @@ class PhpBridgeInterface { virtual std::string getPhpInfo() const = 0; virtual std::string_view getPhpSapiName() const = 0; - + virtual bool isExtensionLoaded(std::string_view extensionName) const = 0; }; } diff --git a/agent/native/libphpbridge/code/Debugging.cpp b/agent/native/libphpbridge/code/Debugging.cpp index e693aaf76..f52cbfc75 100644 --- a/agent/native/libphpbridge/code/Debugging.cpp +++ b/agent/native/libphpbridge/code/Debugging.cpp @@ -5,11 +5,15 @@ #include
#include #include +#include namespace elasticapm::php { using namespace std::string_view_literals; +bool PhpBridge::isExtensionLoaded(std::string_view extensionName) const { + return zend_hash_str_find(&module_registry, extensionName.data(), extensionName.length()) != nullptr; +} static int getModuleData(zval *item, void *arg) { zend_module_entry *module = (zend_module_entry *)Z_PTR_P(item); @@ -64,7 +68,7 @@ std::string PhpBridge::getPhpInfo() const { std::string output; phpInfoTempBuffer = &output; - + auto orig_php_info_as_text = sapi_module.phpinfo_as_text; sapi_module.phpinfo_as_text = 1; diff --git a/agent/native/libphpbridge/code/PhpBridge.h b/agent/native/libphpbridge/code/PhpBridge.h index 221d90cd4..f28e92070 100644 --- a/agent/native/libphpbridge/code/PhpBridge.h +++ b/agent/native/libphpbridge/code/PhpBridge.h @@ -17,6 +17,7 @@ class PhpBridge : public PhpBridgeInterface { std::string getPhpInfo() const final; std::string_view getPhpSapiName() const final; + bool isExtensionLoaded(std::string_view extensionName) const final; protected: zend_class_entry *findClassEntry(std::string_view className) const; diff --git a/docs/setup.asciidoc b/docs/setup.asciidoc index fb4d27024..a426d0cfe 100644 --- a/docs/setup.asciidoc +++ b/docs/setup.asciidoc @@ -120,3 +120,8 @@ the installation directory of the agent (by default `/opt/elastic/apm-agent-php` must be located within a path included in the https://www.php.net/manual/en/ini.core.php#ini.open-basedir[`open_basedir`] value. Otherwise, the agent will not be loaded correctly. + +[discrete] +[[limitation-xdebug]] +==== `Xdebug` stability and memory issues +We strongly advise against running the agent alongside the xdebug extension. Using both extensions simultaneously can lead to stability issues in the instrumented application, such as memory leaks. It is highly recommended to disable xdebug, preferably by preventing it from loading in the `php.ini` configuration file. \ No newline at end of file