Debugging gRPC Applications

1. Enabling Verbose Logging

Env VarEffect
GRPC_GO_LOG_VERBOSITY_LEVEL=99Max verbosity (Go)
GRPC_GO_LOG_SEVERITY_LEVEL=infoSet severity
GRPC_TRACE=allC-core tracing
GRPC_VERBOSITY=DEBUGC-core verbosity

2. Using grpc.EnableTracing

Example: Enable internal tracing

import "google.golang.org/grpc"
grpc.EnableTracing = true
// Expose /debug/requests via golang.org/x/net/trace

3. Inspecting Wire Traffic with tcpdump

Example: Capture gRPC traffic

sudo tcpdump -i lo -w grpc.pcap port 50051
# Open in Wireshark; decode as HTTP/2

4. Using Wireshark for gRPC

SetupDetail
Decode-asRight-click → Decode as → HTTP/2
Add .protoPreferences → Protobuf → Add search path
TLS keysSet SSLKEYLOGFILE env to decrypt

5. Debugging Connection Issues

SymptomCheck
UNAVAILABLE on dialServer up? Firewall? Wrong port?
TLS handshake failCert chain, SNI, ALPN h2
Name resolutionDNS, resolver scheme
Use channelzInspect subchannel states

6. Debugging TLS Issues

ToolDetail
openssl s_client -alpn h2 -connect host:443Verify TLS + ALPN
grpcurl -insecureQuick check ignoring verify
Check SANCert must list server hostname in SAN

7. Debugging Performance Issues

ToolDetail
pprofCPU / heap / goroutine profiles
channelzPer-channel/socket metrics
TracingSpot slow downstream calls

8. Using pprof for Profiling

Example: Enable pprof

import _ "net/http/pprof"
go http.ListenAndServe("localhost:6060", nil)
// go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30

9. Debugging Memory Leaks

CauseDetail
Leaked streamsAlways Close/Drain client streams
Goroutine leakCancel ctx on shutdown paths
Large message retentionAvoid holding response refs in caches
Toolgo tool pprof -alloc_space

10. Using gRPC Channelz

Example: Enable channelz

import "google.golang.org/grpc/channelz/service"
service.RegisterChannelzServiceToServer(srv)
// Use grpcdebug: grpcdebug localhost:50051 channelz channels
InfoDetail
ChannelsTop-level client conns
SubchannelsPer-endpoint state
SocketsBytes sent/received, flow control
ServersActive call counts