In this example, we will start two gRPC user-server and after-server and implement distributed logging.
go get github.com/rookie-ninja/rk-boot/v2
go get github.com/rookie-ninja/rk-grpc/v2
app:
name: userServer
grpc:
- name: userServer
enabled: true
port: 2008
enableReflection: true
enableRkGwOption: true
sw:
enabled: true
path: "sw"
jsonPath: "api/gen/v1"
middleware:
trace:
enabled: true
exporter:
jaeger:
agent:
enabled: false
collector:
enabled: true
logging:
enabled: true
app:
name: afterServer # 为了能让 jaeger 辨别不同的服务,这里必须取名,否则为:rk
grpc:
- name: afterServer
enabled: true
port: 2022
enableReflection: true
enableRkGwOption: true
sw:
enabled: true
path: "sw"
jsonPath: "api/gen/v1"
middleware:
trace:
enabled: true
exporter:
jaeger:
agent:
enabled: false
collector:
enabled: true
logging:
enabled: true
Please refer to user-server.go, grpc-serverB.go and http-server.go
$ go run user-server.go
$ go run after-server.go
curl -X GET 'http://localhost:2008/v1/user/create?name=hihi'
{"traceId":"96ef777f259322d758821919529ec8cc"}
- check logs at user-server
------------------------------------------------------------------------
...
ids={"eventId":"96becb7b-8ddb-4e64-91ed-869022913487","traceId":"96ef777f259322d758821919529ec8cc"}
...
operation=/api.v1.User/CreateUser
...
- check logs at task server
traceId: 96ef777f259322d758821919529ec8cc
- check logs at after-server
------------------------------------------------------------------------
...
ids={"eventId":"a75d0c6d-b54d-476a-b16c-f4ede087ef3a","traceId":"96ef777f259322d758821919529ec8cc"}
...
operation=/api.v1.After/CreateAfter
...