Skip to content

Commit 5a34302

Browse files
committed
update README
1 parent a0d1e25 commit 5a34302

File tree

3 files changed

+3
-32
lines changed

3 files changed

+3
-32
lines changed

README.md

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -134,38 +134,7 @@ newRpcServiceReq(tracer)
134134
```
135135

136136
### Http to gRPC tracing
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-
```
137+
![http to grpc client](wiki/imgs/httptogrpc_client.jpg)
169138
**ptx** is parent context, it can create sub-context trace span <br>
170139
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) .
171140

example/http/httpServer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func RpcClient(ptx context.Context) string {
3838
rpcOption, closer := tracing.AddRpcClientTracing(
3939
"RpcClient",
4040
map[string]string{"version": "v1"})
41+
// or map[string]string{"traceType": "zipkin", "version": "v1"}), traceType : jaeger (default) or zipkin
42+
// or export TRACE_TYPE=zipkin or jaeger
4143
defer closer.Close()
4244
address := "localhost:22530"
4345
conn, err := grpc.Dial(address, grpc.WithInsecure(), rpcOption)

wiki/imgs/httptogrpc_client.jpg

75.7 KB
Loading

0 commit comments

Comments
 (0)