Golang GRPC Practice serial six built-in trace

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Built-in trace

Grpc default provides the client and server trace log, unfortunately does not provide a custom interface, currently can only view the basic event log and request log, for basic request status Review is also very helpful, the client and the server is basically the same, here is the server opened trace for example, To modify the server code for the Hello project:

Server/main.go

Package Mainimport ("NET" "Net/http" PB "Git.vodjk.com/go-grpc/example/proto"//introduce compilation-generated packages "golang.org/x/net/c    Ontext "Golang.org/x/net/trace"//Introduction Trace Package "Google.golang.org/grpc" "Google.golang.org/grpc/grpclog") const ( Address GRPC addresses = "127.0.0.1:50052")//define HelloService and implement the agreed interface type HelloService struct{}//helloservice. . var HelloService = Helloservice{}func (H helloservice) SayHello (CTX context. Context, in *PB. Hellorequest) (*PB. Helloreply, error) {resp: = new (Pb). helloreply) resp. Message = "Hello" + in.    Name + "." Return resp, Nil}func main () {listen, err: = Net. Listen ("TCP", Address) if err! = Nil {grpclog. Fatalf ("Failed to listen:%v", err)}//Instantiate Grpc Server s: = Grpc. NewServer ()//Registered HelloService PB. Registerhelloserver (S, helloservice)//Turn on trace Go starttrace () grpclog. Println ("Listen on" + Address) S.serve (Listen)}func starttrace () {trace. Authrequest = func (req *http. Request) (ANY, sensitive bool) {return true, true} go http. Listenandserve (": 50051", nil) grpclog. Println ("Trace Listen on 50051")}

Here we open an HTTP service listening on port 50051 to see the trace information of the GRPC request

Run:

go run main.goListen on 127.0.0.1:50052                                                       Trace listen on 50051// 进入client目录执行一次客户端请求     

Server-side Event view

Visit: localhost:50051/debug/events, results

You can see the event information for services and services that are registered on the server to start properly, and this is the only event in the default trace

Request Log Information view

Visit: localhost:50051/debug/requests, results

The most recent request status can be shown here, including the requested service, parameters, time-consuming, response, and convenient for simple state viewing, with the default value showing the last 10 records and cannot be modified.

Reference

Sample code for this series

    • Go-grpc-example

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.