|
9 | 9 | traceandtrace-go is go tracing lib. It integrate multi tracer such as jeager,zipkin,skywalking and so on <br> |
10 | 10 |
|
11 | 11 | ## Version introduction |
12 | | -- v1.0.0 only support jeager |
| 12 | +### v1.0.0 |
| 13 | +- only support jeager |
13 | 14 | - support http and gRPC (or both) tracing |
14 | 15 | - support sampler, sampler type and collector env setting |
15 | 16 |
|
16 | | -## Version introduction |
17 | | -- v1.0.3 support jeager and zipkin |
| 17 | +### v1.0.3 |
| 18 | +- support jeager and zipkin |
18 | 19 |
|
19 | 20 | ## API |
20 | 21 | [godoc](https://pkg.go.dev/github.com/codeandcode0x/traceandtrace-go) |
@@ -82,7 +83,7 @@ Create a trace on the http request method side. |
82 | 83 | tags are map[string]string type, you can pass logs k-v, tag and field. |
83 | 84 |
|
84 | 85 |
|
85 | | -### RPC tracing |
| 86 | +### gRPC tracing |
86 | 87 | Create a trace on the rpc request method side |
87 | 88 |
|
88 | 89 | **client** |
@@ -133,8 +134,40 @@ newRpcServiceReq(tracer) |
133 | 134 | ``` |
134 | 135 |
|
135 | 136 | ### Http to gRPC tracing |
136 | | - |
137 | | -To call gRPC on the http server side, you need to add the parent context to the rpc client. For details, you can see the [example](example/http/httpServer.go) . |
| 137 | +```go |
| 138 | +//grpc request |
| 139 | +func RpcClient(ptx context.Context) string { |
| 140 | + rpcOption, closer := tracing.AddRpcClientTracing( |
| 141 | + "RpcClient", |
| 142 | + map[string]string{"version": "v1"}) |
| 143 | + // or map[string]string{"traceType": "zipkin", "version": "v1"}), traceType : jaeger (default) or zipkin |
| 144 | + // or export TRACE_TYPE=zipkin or jaeger |
| 145 | + defer closer.Close() |
| 146 | + address := "localhost:22530" |
| 147 | + conn, err := grpc.Dial(address, grpc.WithInsecure(), rpcOption) |
| 148 | + if err != nil { |
| 149 | + } |
| 150 | + defer conn.Close() |
| 151 | + c := pb.NewGreeterClient(conn) |
| 152 | + // Contact the server and print out its response. |
| 153 | + name := "rpc test" |
| 154 | + if len(os.Args) > 1 { |
| 155 | + name = os.Args[1] |
| 156 | + } |
| 157 | + // use parent context |
| 158 | + ctx, cancel := context.WithTimeout(ptx, time.Second) |
| 159 | + defer cancel() |
| 160 | + r, err := c.SayHello(ctx, &pb.HelloRequest{Name: name}) |
| 161 | + if err != nil { |
| 162 | + log.Println("error:", err) |
| 163 | + } |
| 164 | + |
| 165 | + log.Printf("Greeting: %s", r.Message) |
| 166 | + return r.Message |
| 167 | +} |
| 168 | +``` |
| 169 | +**ptx** is parent context, it can create sub-context trace span <br> |
| 170 | +To call gRPC on the http server side, you need to add the parent context to the gRPC client. For details, you can see the [example](example/http/httpServer.go) . |
138 | 171 |
|
139 | 172 | ## Concurrent Processing |
140 | 173 | ### goroutine context control |
|
0 commit comments