Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added warning log for Xdebug incompatibility (#1256) #1257

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-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.
Loading