https://github.com/cloudwego/kitex-examples/blob/main/opentelemetry/docker-compose.yaml
下载两个yaml文件:docker-compose.yaml otel-collector-config.yaml
在该目录下执行
docker-compose up -d
How To Run
Docker
Ensure Docker has been installed.
Run opentelemetry-collector, jaeger, victoriametrics, grafana
docker-compose up -d
Run Kitex server
go run server/main.go
Run Kitex client
go run client/main.go
Monitoring
监控
You can then navigate to http://localhost:16686 to access the Jaeger UI. (You can visit Monitor Jaeger for details)
查看指标
You can then navigate to http://localhost:3000 to access the Grafana UI. (You can visit Monitor Grafana for metrics)
数据源
Http URL:
http://victoriametrics:8428/
Add A Dashboard And A Panel
增加数据平面
Support Metrics
- RPC Metrics
- Runtime Metrics
Tracing Associated Logs
Set Logger Impl
import (
kitexlogrus "github.com/kitex-contrib/obs-opentelemetry/logging/logrus"
)
func init() {
klog.SetLogger(kitexlogrus.NewLogger())
klog.SetLevel(klog.LevelDebug)
}
Log With Context
// Echo implements the Echo interface.
func (s *EchoImpl) Echo(ctx context.Context, req *api.Request) (resp *api.Response, err error) {
klog.CtxDebugf(ctx, "echo called: %s", req.GetMessage())
return &api.Response{Message: req.Message}, nil
}
view log
{"level":"debug","msg":"echo called: my request","span_id":"056e0cf9a8b2cec3","time":"2022-03-09T02:47:28+08:00","trace_flags":"01","trace_id":"33bdd3c81c9eb6cbc0fbb59c57ce088b"}
Work with Jaeger
Jaeger natively supports OTLP protocol, and we can send data directly to Jaeger without OpenTelemetry Collector
Jaeger Architecture
Image from jaeger
Demo
Run Jaeger with COLLECTOR_OTLP_ENABLED
version: "3.7"
services:
# Jaeger
jaeger-all-in-one:
image: jaegertracing/all-in-one:latest
environment:
- COLLECTOR_OTLP_ENABLED=true
ports:
- "4317:4317" # OTLP gRPC receiver
Config Exporter with Environment
export OTEL_EXPORTER_OTLP_ENDPOINT=http://host.docker.internal:4317
export OTEL_EXPORTER_OTLP_PROTOCOL=grpc