diff --git a/prod/native/libcommon/code/Logger.cpp b/prod/native/libcommon/code/Logger.cpp index f25af9a..8e8aeb7 100644 --- a/prod/native/libcommon/code/Logger.cpp +++ b/prod/native/libcommon/code/Logger.cpp @@ -27,6 +27,14 @@ namespace elasticapm::php { +LogLevel Logger::getMaxLogLevel() const { + auto maxLevel = LogLevel::logLevel_off; + for (auto const &sink : sinks_) { + maxLevel = std::max(sink->getLevel(), maxLevel); + } + return maxLevel; +} + bool Logger::doesMeetsLevelCondition(LogLevel level) const { auto maxLevel = LogLevel::logLevel_off; for (auto const &sink : sinks_) { diff --git a/prod/native/libcommon/code/Logger.h b/prod/native/libcommon/code/Logger.h index 8250ccb..41b92ab 100644 --- a/prod/native/libcommon/code/Logger.h +++ b/prod/native/libcommon/code/Logger.h @@ -74,6 +74,8 @@ class Logger : public LoggerInterface { void attachSink(std::shared_ptr sink); + LogLevel getMaxLogLevel() const; + private: std::string getFormattedTime() const; std::string getFormattedProcessData() const; diff --git a/prod/native/libcommon/code/LoggerInterface.h b/prod/native/libcommon/code/LoggerInterface.h index e83f424..18f2698 100644 --- a/prod/native/libcommon/code/LoggerInterface.h +++ b/prod/native/libcommon/code/LoggerInterface.h @@ -32,6 +32,7 @@ class LoggerInterface { virtual void printf(LogLevel level, const char *format, ...) const = 0; virtual bool doesMeetsLevelCondition(LogLevel level) const = 0; + virtual LogLevel getMaxLogLevel() const = 0; }; diff --git a/prod/native/libcommon/code/RequestScope.h b/prod/native/libcommon/code/RequestScope.h index 3be44a1..dbaf175 100644 --- a/prod/native/libcommon/code/RequestScope.h +++ b/prod/native/libcommon/code/RequestScope.h @@ -42,6 +42,8 @@ class RequestScope { void onRequestInit() { ELOG_DEBUG(log_, __FUNCTION__); + resetRequest(); + if (!sapi_->isSupported()) { ELOG_DEBUG(log_, "SAPI '%s' not supported", sapi_->getName().data()); return; @@ -54,7 +56,6 @@ class RequestScope { return; } - resetRequest(); requestCounter_++; auto requestStartTime = std::chrono::system_clock::now(); @@ -110,6 +111,8 @@ class RequestScope { void onRequestPostDeactivate() { ELOG_DEBUG(log_, __FUNCTION__); + resetRequest(); + if (!bootstrapSuccessfull_) { return; } @@ -132,7 +135,7 @@ class RequestScope { using namespace std::string_view_literals; try { bridge_->compileAndExecuteFile((*config_)->bootstrap_php_part_file); - bridge_->callPHPSideEntryPoint(LogLevel::logLevel_trace, requestStartTime); + bridge_->callPHPSideEntryPoint(log_->getMaxLogLevel(), requestStartTime); } catch (std::exception const &e) { ELOG_CRITICAL(log_, "Unable to bootstrap PHP-side instrumentation '%s'", e.what()); return false;