Skip to content

Commit

Permalink
Added warning log for Xdebug incompatibility (elastic#1256)
Browse files Browse the repository at this point in the history
  • Loading branch information
intuibase committed Jan 9, 2025
1 parent 159b758 commit c2ce4fb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
17 changes: 12 additions & 5 deletions agent/native/ext/lifecycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion agent/native/libcommon/code/PhpBridgeInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

}
6 changes: 5 additions & 1 deletion agent/native/libphpbridge/code/Debugging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
#include <main/SAPI.h>
#include <Zend/zend_modules.h>
#include <Zend/zend_extensions.h>
#include <Zend/zend_string.h>

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);

Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions agent/native/libphpbridge/code/PhpBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions docs/setup.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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-open_basedir]]
==== `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.

0 comments on commit c2ce4fb

Please sign in to comment.