如何调试grpc调用?

时间:2016-05-09 21:44:28

标签: grpc

我正在试图找出为什么我的grpc调用不起作用,但我无法弄清楚如何打开调试,所以我可以看到通过grpc发送和接收的数据连接。

如何启用grpc调用的调试?

5 个答案:

答案 0 :(得分:32)

您可以将GRPC_TRACE环境变量设置为all,让grpc转储一大堆关于连接正在做什么的数据:

export GRPC_TRACE=all

从评论中修改:显然您还需要设置:

export GRPC_VERBOSITY=DEBUG

答案 1 :(得分:4)

在Golang中,您需要设置GODEBUG environment variable以查看HTTP2跟踪,即由gRPC设置的标头:

GODEBUG=http2debug=1   # enable verbose HTTP/2 debug logs
GODEBUG=http2debug=2   # ... even more verbose, with frame dumps

然后输出将发送到stdout。这是一个例子:

{"level":"info","msg":"2017/06/11 08:52:20 http2: Framer 0xc42009c0e0: wrote SETTINGS len=0","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: Framer 0xc42009c0e0: wrote WINDOW_UPDATE len=4 (conn) incr=983025","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: Framer 0xc42009c0e0: read SETTINGS len=18, settings: ENABLE_PUSH=0, MAX_CONCURRENT_STREAMS=0, INITIAL_WINDOW_SIZE=1048576","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: Framer 0xc42009c0e0: read WINDOW_UPDATE len=4 (conn) incr=983041","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: Framer 0xc42009c0e0: wrote SETTINGS flags=ACK len=0","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: Framer 0xc42009c0e0: read SETTINGS flags=ACK len=0","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: Framer 0xc42009c0e0: read HEADERS flags=END_HEADERS|PRIORITY stream=3 len=249","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: decoded hpack field header field \":authority\" = \"\"","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: decoded hpack field header field \":path\" = \"/internal.push.v1.UnifiedDevicePush/SendMessage\"","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: decoded hpack field header field \":method\" = \"POST\"","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: decoded hpack field header field \":scheme\" = \"http\"","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: decoded hpack field header field \"content-type\" = \"application/grpc\"","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: decoded hpack field header field \"te\" = \"trailers\"","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: decoded hpack field header field \"user-agent\" = \"grpc-java-netty/1.0.3\"","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: decoded hpack field header field \"root-common.xirequestid-bin\" = \"ChIJzE6lBfCTCsYRoIIJujc92JY=\"","time":"2017-06-11T08:52:20Z"}
{"level":"info","msg":"2017/06/11 08:52:20 http2: decoded hpack field header field \"te\" = \"trailers\"","time":"2017-06-11T08:52:20Z"}

答案 2 :(得分:3)

导出 GRPC_GO_LOG_VERBOSITY_LEVEL=99
导出 GRPC_GO_LOG_SEVERITY_LEVEL=info

用最新的 grpc go 版本试试这个。

答案 3 :(得分:2)

来自docs

<块引用>

GRPC_VERBOSITY 用于设置 gRPC 打印的日志消息的最低级别(支持的值为 DEBUGINFOERROR)。如果未设置此环境变量,则只会打印 ERROR 日志。

另外,检查 GRPC_TRACE

有 15+ 个 grpc 环境 variables

Windows 用户的说明,引用自 docs

已知限制:GPRC_TRACE=tcp 目前未在 Windows 上实现(您不会看到任何 TCP 跟踪)。

答案 4 :(得分:1)

您可以使用 Mediator 工具调试和跟踪 gRPC 调用。

它是一个类似于 charles 的 GUI 工具,但是如果您需要解析 protobuf 消息体,gRPC 服务器需要支持 Server Reflection