Commit 811b7b5e authored by Bob Van Landuyt's avatar Bob Van Landuyt 💬
Browse files

Merge branch 'sh-log-exception-backtrace' into 'master'

Log exception backtrace in gRPC server logging interceptor

See merge request gitlab-org/labkit-ruby!58
parents 6cfdba1b e08a2988
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -77,7 +77,10 @@ module Labkit
            time: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ"),
          )

          message["exception"] = ex.message if ex
          if ex
            message["exception"] = ex.message
            message["exception_backtrace"] = ex.backtrace[0..5] if ex.backtrace
          end

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

        expect(result).to include("grpc.code" => "DataLoss")
        expect(result).to include("exception" => "15:test exception")
        expect(result["exception_backtrace"]).to be_a(Array)
      end

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

        expect(result).to include("grpc.code" => "Unknown")
        expect(result).to include("exception" => "-1")
        expect(result["exception_backtrace"]).to be_a(Array)
      end
    end
  end