From 4c841c1c55ea98f22806b19cdb9a7efbab43dc0f Mon Sep 17 00:00:00 2001
From: Pavel Pautov
Date: Wed, 17 Jul 2024 16:34:06 -0700
Subject: [PATCH] Use Abseil logging for gRPC v1.65.0 and above.
Original logging method is now deprecated and results in error message
on Nginx startup.
---
src/grpc_log.cpp | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/src/grpc_log.cpp b/src/grpc_log.cpp
index 84d796ca..bb833644 100644
--- a/src/grpc_log.cpp
+++ b/src/grpc_log.cpp
@@ -2,8 +2,8 @@
#include "grpc_log.hpp"
-#include
#include
+#include
#if GOOGLE_PROTOBUF_VERSION < 4022000
@@ -36,9 +36,9 @@ class ProtobufLog {
#include
#include
-class ProtobufLog : absl::LogSink {
+class NgxLogSink : absl::LogSink {
public:
- ProtobufLog()
+ NgxLogSink()
{
absl::InitializeLog();
absl::AddLogSink(this);
@@ -46,7 +46,7 @@ class ProtobufLog : absl::LogSink {
absl::SetStderrThreshold(static_cast(100));
}
- ~ProtobufLog() override { absl::RemoveLogSink(this); }
+ ~NgxLogSink() override { absl::RemoveLogSink(this); }
void Send(const absl::LogEntry& entry) override
{
@@ -61,12 +61,19 @@ class ProtobufLog : absl::LogSink {
ngx_str_t message { entry.text_message().size(),
(u_char*)entry.text_message().data() };
- ngx_log_error(level, ngx_cycle->log, 0, "OTel/protobuf: %V", &message);
+ ngx_log_error(level, ngx_cycle->log, 0, "OTel/grpc: %V", &message);
}
};
+typedef NgxLogSink ProtobufLog;
+
#endif
+#if (GRPC_CPP_VERSION_MAJOR < 1) || \
+ (GRPC_CPP_VERSION_MAJOR == 1 && GRPC_CPP_VERSION_MINOR < 65)
+
+#include
+
class GrpcLog {
public:
GrpcLog() { gpr_set_log_function(grpcLogHandler); }
@@ -87,6 +94,13 @@ class GrpcLog {
ProtobufLog protoLog;
};
+#else
+
+// newer gRPC implies newer protobuf, and both use Abseil for logging
+typedef NgxLogSink GrpcLog;
+
+#endif
+
void initGrpcLog()
{
static GrpcLog init;