Skip to content

Commit

Permalink
Fixed hooking resource release and passing correct log level to boots…
Browse files Browse the repository at this point in the history
…trap
  • Loading branch information
intuibase committed Sep 10, 2024
1 parent 57c3848 commit 166dd5f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions prod/native/libcommon/code/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down
2 changes: 2 additions & 0 deletions prod/native/libcommon/code/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class Logger : public LoggerInterface {

void attachSink(std::shared_ptr<LoggerSinkInterface> sink);

LogLevel getMaxLogLevel() const;

private:
std::string getFormattedTime() const;
std::string getFormattedProcessData() const;
Expand Down
1 change: 1 addition & 0 deletions prod/native/libcommon/code/LoggerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};


Expand Down
7 changes: 5 additions & 2 deletions prod/native/libcommon/code/RequestScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,7 +56,6 @@ class RequestScope {
return;
}

resetRequest();
requestCounter_++;

auto requestStartTime = std::chrono::system_clock::now();
Expand Down Expand Up @@ -110,6 +111,8 @@ class RequestScope {
void onRequestPostDeactivate() {
ELOG_DEBUG(log_, __FUNCTION__);

resetRequest();

if (!bootstrapSuccessfull_) {
return;
}
Expand All @@ -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;
Expand Down

0 comments on commit 166dd5f

Please sign in to comment.