Commit 6cfdba1b authored by Bob Van Landuyt's avatar Bob Van Landuyt 💬
Browse files

Merge branch 'smh-log-grpc-errors' into 'master'

Log exceptions in gRPC server logging interceptor

Closes #19

See merge request gitlab-org/labkit-ruby!55
parents b2512b79 db7d6143
Loading
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