Skip to content

Commit a0d1e25

Browse files
committed
update README
1 parent c4f4e7f commit a0d1e25

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

README.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
traceandtrace-go is go tracing lib. It integrate multi tracer such as jeager,zipkin,skywalking and so on <br>
1010

1111
## Version introduction
12-
- v1.0.0 only support jeager
12+
### v1.0.0
13+
- only support jeager
1314
- support http and gRPC (or both) tracing
1415
- support sampler, sampler type and collector env setting
1516

16-
## Version introduction
17-
- v1.0.3 support jeager and zipkin
17+
### v1.0.3
18+
- support jeager and zipkin
1819

1920
## API
2021
[godoc](https://pkg.go.dev/github.com/codeandcode0x/traceandtrace-go)
@@ -82,7 +83,7 @@ Create a trace on the http request method side.
8283
tags are map[string]string type, you can pass logs k-v, tag and field.
8384

8485

85-
### RPC tracing
86+
### gRPC tracing
8687
Create a trace on the rpc request method side
8788

8889
**client**
@@ -133,8 +134,40 @@ newRpcServiceReq(tracer)
133134
```
134135

135136
### Http to gRPC tracing
136-
![http to grpc client](wiki/imgs/httptogrpc_client.jpg)
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) .
138171

139172
## Concurrent Processing
140173
### goroutine context control

0 commit comments

Comments
 (0)