• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# gRPC Python Debug Example
2
3This example demonstrate the usage of Channelz. For a better looking website,
4the [gdebug](https://github.com/grpc/grpc-experiments/tree/master/gdebug) uses
5gRPC-Web protocol and will serve all useful information in web pages.
6
7## Channelz: Live Channel Tracing
8
9Channelz is a channel tracing feature. It will track statistics like how many
10messages have been sent, how many of them failed, what are the connected
11sockets. Since it is implemented in C-Core and has low-overhead, it is
12recommended to turn on for production services. See [Channelz design
13doc](https://github.com/grpc/proposal/blob/master/A14-channelz.md).
14
15## How to enable tracing log
16The tracing log generation might have larger overhead, especially when you try
17to trace transport. It would result in replicating the traffic loads. However,
18it is still the most powerful tool when you need to dive in.
19
20### The Most Verbose Tracing Log
21
22Specify environment variables, then run your application:
23
24```
25GRPC_VERBOSITY=debug
26GRPC_TRACE=all
27```
28
29For more granularity, please see
30[environment_variables](https://github.com/grpc/grpc/blob/master/doc/environment_variables.md).
31
32### Debug Transport Protocol
33
34```
35GRPC_VERBOSITY=debug
36GRPC_TRACE=tcp,http,secure_endpoint,transport_security
37```
38
39### Debug Connection Behavior
40
41```
42GRPC_VERBOSITY=debug
43GRPC_TRACE=call_error,connectivity_state,pick_first,round_robin,glb
44```
45
46## How to debug your application?
47
48`pdb` is a debugging tool that is available for Python interpreters natively.
49You can set breakpoint, and execute commands while the application is stopped.
50
51The simplest usage is add a single line in the place you want to inspect:
52`import pdb; pdb.set_trace()`. When interpreter see this line, it would pop out
53a interactive command line interface for you to inspect the application state.
54
55For more detailed usage, see https://docs.python.org/3/library/pdb.html.
56
57**Caveat**: gRPC Python uses C-Extension under-the-hood, so `pdb` may not be
58able to trace through the whole stack.
59
60## gRPC Command Line Tool
61
62`grpc_cli` is a handy tool to interact with gRPC backend easily. Imageine you can
63inspect what service does a server provide without writing any code, and make
64gRPC calls just like `curl`.
65
66The installation guide: https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md#code-location
67The usage guide: https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md#usage
68The source code: https://github.com/grpc/grpc/blob/master/test/cpp/util/grpc_cli.cc
69