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

Fixed hooking resource release and passing correct log level to bootstrap #88

Merged
merged 1 commit into from
Sep 11, 2024
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
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