Commit db7d6143 authored by Sami Hiltunen's avatar Sami Hiltunen Committed by Bob Van Landuyt
Browse files

log exceptions in gRPC server logging interceptor

gRPC server logging interceptor currently only logs status codes but
not the exception messages. This makes it more difficult to correlate
failed RPCs with the exceptions that failed them. This is especially
with CallErrors as they cause the gRPC server not to respond to the
client. This commit logs any raised exceptions under the 'exception'
field.
parent b2512b79
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ module Labkit
            time: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ"),
          )

          message["exception"] = ex.message if ex

          @log_file.puts(JSON.dump(message))
        end
      end
+6 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ describe Labkit::Logging::GRPC::ServerInterceptor do
        end

        expect(result).to include("grpc.code" => "OK")
        expect(result).not_to include("exception")
      end
    end

@@ -35,6 +36,7 @@ describe Labkit::Logging::GRPC::ServerInterceptor do
        end

        expect(result).to include("grpc.code" => "OK")
        expect(result).not_to include("exception")
      end
    end

@@ -45,6 +47,7 @@ describe Labkit::Logging::GRPC::ServerInterceptor do
        end

        expect(result).to include("grpc.code" => "OK")
        expect(result).not_to include("exception")
      end
    end

@@ -56,6 +59,7 @@ describe Labkit::Logging::GRPC::ServerInterceptor do
        end

        expect(result).to include("grpc.code" => "OK")
        expect(result).not_to include("exception")
      end
    end

@@ -103,6 +107,7 @@ describe Labkit::Logging::GRPC::ServerInterceptor do
        end

        expect(result).to include("grpc.code" => "DataLoss")
        expect(result).to include("exception" => "15:test exception")
      end

      it "logs other exceptions as Unknown" do
@@ -113,6 +118,7 @@ describe Labkit::Logging::GRPC::ServerInterceptor do
        end

        expect(result).to include("grpc.code" => "Unknown")
        expect(result).to include("exception" => "-1")
      end
    end
  end