Skip to content

Commit 952ba56

Browse files
committed
add godoc
1 parent 5491597 commit 952ba56

File tree

2 files changed

+41
-68
lines changed

2 files changed

+41
-68
lines changed

README.md

Lines changed: 41 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# 微服务架构 —— 分布式链路追踪
1+
# MSA Distributed link tracking
2+
微服务架构 —— 分布式链路追踪
23

3-
## 简介
4-
traceandtrace-go go 语言 tracing lib, 可以集成不同的 tracer 如: jeagerzipkinskywalking ... <br>
4+
## Introduction
5+
traceandtrace-go is go tracing lib. It integrate multi tracer such as jeager,zipkin,skywalking and so on <br>
56

6-
## 版本介绍
7-
- v1.0.0 目前只支持 jeager
8-
- 支持 http gRPC (or both) 调用链路
9-
- 支持采样率、采样类型、收集器等配置
7+
## Version introduction
8+
- v1.0.0 only support jeager
9+
- support http and gRPC (or both) tracing
10+
- support sampler, sampler type and collector env setting
1011

1112
## API
1213

1314

15+
## quick start
1416

15-
## 快速开始
16-
17-
### 启动 Jaeger
17+
### start jaeger
1818

1919
```shell
2020
docker run \
@@ -28,122 +28,95 @@ ethansmart-docker.pkg.coding.net/istioalltime/roandocker/jaegertracing-all-in-on
2828

2929
```
3030

31-
### 引入 SDK 包
31+
### import package
3232

3333
```shell
3434
go get github.com/codeandcode0x/traceandtrace-go
3535
```
3636

37+
### HTTP tracing
3738

39+
Create a trace on the http request method side.
40+
![http to grpc client](wiki/imgs/http_client.jpg)
41+
tags are map[string]string type, you can pass logs k-v, tag and field.
3842

39-
### HTTP 请求链路
40-
在 http request 方法侧创建 trace
41-
42-
代码如下:
43-
- **client 端**
44-
45-
```go
46-
import (
47-
tracing "github.com/codeandcode0x/traceandtrace-go"
48-
)
4943

44+
### RPC tracing
45+
Create a trace on the rpc request method side
5046

51-
// 在 func 中 或者 middleware 中添加
52-
_, cancel := tracing.AddHttpTracing("HttpTracingTest", [your http Header], map[string]string{"version": "v1"})
53-
defer cancel()
54-
55-
```
56-
57-
- **server 端**
47+
- **client**
5848

5949
```go
6050
import (
6151
tracing "github.com/codeandcode0x/traceandtrace-go"
6252
)
6353

64-
// 在 func 中 或者 middleware 中添加
65-
_, cancel := tracing.AddHttpTracing("HttpTracingTest", [your http Header], map[string]string{"version": "v1"})
66-
defer cancel()
67-
68-
...
69-
```
70-
tags 为 map[string]string 类型, 可以传递 logs k-v, tag 和 field
71-
72-
73-
### RPC 请求链路
74-
在 rpc request 方法侧创建 trace
75-
76-
- **client 端**
77-
78-
```go
79-
import (
80-
tracing "github.com/codeandcode0x/traceandtrace-go"
81-
)
82-
83-
//创建 rpc options
54+
// create rpc options
8455
rpcOption, closer := tracing.AddRpcClientTracing("RpcClientExample")
8556
defer closer.Close()
8657

87-
//dial
58+
// dial
8859
conn, err := grpc.Dial(addr, grpc.WithInsecure(), rpcOption)
8960
if err != nil {
9061
}
9162
...
9263
```
93-
- **server**
64+
- **server**
9465

9566
```go
9667
import (
9768
tracing "github.com/codeandcode0x/traceandtrace-go/wrapper/rpc"
9869
)
9970

100-
//不需要请求别的 rpc 服务
71+
//No need to request other rpc services
10172
rpcOption, closer, _ := rpcTracing.AddRpcServerTracing(serviceName)
10273
defer closer.Close()
10374

104-
//在 server 端监听进程中加入 rpcOptions 即可
75+
//Add rpcOptions to the server-side monitoring process
10576
s := grpc.NewServer(rpcOption)
10677

107-
//------------------------------------------------
78+
```
79+
80+
Need to request another rpc service
10881

109-
//需要请求别的 rpc 服务
82+
```go
11083
rpcOption, closer, tracer := rpcTracing.AddRpcServerTracing(serviceName)
11184
defer closer.Close()
11285

113-
//在 server 端监听进程中加入 rpcOptions 即可
86+
//Add rpcOptions to the server-side monitoring process
11487
s := grpc.NewServer(rpcOption)
11588
//rpc 请求
11689
newRpcServiceReq(tracer)
11790

11891
...
11992
```
12093

121-
### Http to gRPC 链路
94+
### Http to gRPC tracing
12295
![http to grpc client](wiki/imgs/httptogrpc_client.jpg)
123-
http server 端调用 gRPC, 需要在 rpc client 中加入 parent context, 详情可以查看 example 中的示例
96+
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) .
12497

125-
## 并发处理
126-
### 协程 context 管理
98+
## Concurrent Processing
99+
### goroutine context control
127100

128-
- 通过 context.Background() 创建子协程 context, 形成会话树 (协程树), 是线程安全的 (不存在数据竞争问题) ;
129-
- 通过 context WithCancel() 创建子协程会话, 管理协程任务 ;
130-
- 每个 context 会携带父类 trace 和 子 span 的相关 data
101+
- By context.Background() create sub-coroutine context, form a session tree (coroutine tree), which is thread-safe (there is no data race problem) ;
102+
- By context WithCancel() create sub-coroutine sessions and manage coroutine tasks ;
103+
- every context will carry related data of parent trace and child span ;
131104

132-
![goroutine 会话](https://images2018.cnblogs.com/blog/1048291/201806/1048291-20180629074859717-1555813847.png)
105+
![goroutine session](https://images2018.cnblogs.com/blog/1048291/201806/1048291-20180629074859717-1555813847.png)
133106

134-
### 协程 trace job 管理和资源回收
135-
启动和暂停 trace job
107+
### trace job control
108+
start and end trace job
136109

137110
```go
138-
//启动协程 job
111+
// start job
139112
ch := make(chan context.Context, 0)
140113
go doTask(ch, ctx, r, svc, traceType, tags)
141114

142-
//任务结束 (接受信号)
115+
// end job (receive signal)
143116
pctx := <-ch
144117
pch <- pctx
145118

146-
//资源回收 (暂停任务)
119+
// release job
147120
for {
148121
select {
149122
case <-ctx.Done():

wiki/imgs/http_client.jpg

254 KB
Loading

0 commit comments

Comments
 (0)