Commit e08a2988 authored by Stan Hu's avatar Stan Hu
Browse files

Log exception backtrace in gRPC server logging interceptor

In gitlab-org/gitlab#301154, we saw a
gitaly-ruby UTF-8 encoding exception, but it difficult to narrow down
the cause. Even though the backtrace did land in Sentry, in a
development or customer environment this may not be available.

We now log the first 5 lines of an exception backtrace to provide more
context.
parent 6cfdba1b
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