Skip to content
Snippets Groups Projects
Commit 6bb8e8c9 authored by Pavel Pautov's avatar Pavel Pautov Committed by dplotnikov-f5
Browse files

Redirect gRPC and Protobuf logs into Nginx error log.

By default, these libraries may log directly into stderr.
parent cd9c91ac
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,9 @@ extern "C" {
#include <ngx_http.h>
}
#include <grpc/support/log.h>
#include <google/protobuf/stubs/logging.h>
#include "str_view.hpp"
#include "trace_context.hpp"
#include "batch_exporter.hpp"
......@@ -475,6 +478,28 @@ ngx_int_t onRequestEnd(ngx_http_request_t* r)
return NGX_DECLINED;
}
void grpcLogHandler(gpr_log_func_args* args)
{
ngx_uint_t level = args->severity == GPR_LOG_SEVERITY_ERROR ? NGX_LOG_ERR :
args->severity == GPR_LOG_SEVERITY_INFO ? NGX_LOG_INFO :
/*GPR_LOG_SEVERITY_DEBUG*/ NGX_LOG_DEBUG;
ngx_log_error(level, ngx_cycle->log, 0, "OTel/grpc: %s", args->message);
}
void protobufLogHandler(google::protobuf::LogLevel logLevel,
const char* filename, int line, const std::string& msg)
{
using namespace google::protobuf;
ngx_uint_t level = logLevel == LOGLEVEL_FATAL ? NGX_LOG_EMERG :
logLevel == LOGLEVEL_ERROR ? NGX_LOG_ERR :
logLevel == LOGLEVEL_WARNING ? NGX_LOG_WARN :
/*LOGLEVEL_INFO*/ NGX_LOG_INFO;
ngx_log_error(level, ngx_cycle->log, 0, "OTel/protobuf: %s", msg.c_str());
}
ngx_int_t initModule(ngx_conf_t* cf)
{
auto cmcf = (ngx_http_core_main_conf_t*)ngx_http_conf_get_module_main_conf(
......@@ -496,6 +521,9 @@ ngx_int_t initModule(ngx_conf_t* cf)
*h = onRequestEnd;
gpr_set_log_function(grpcLogHandler);
google::protobuf::SetLogHandler(protobufLogHandler);
return NGX_OK;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment