Zipkin : Golang 微服务全链路监控(四)
Golang 微服务全链路监控实现
- broker-service -> auth-service -> postgres db
- zipkin 监控:需代码入侵
使用 zipkin 库的 serverMiddleware,其通过 Http 跟踪(trace)链路。访问 auth-service,需通过 zipkinhttp.NewClient() 方法
zipkinhttp "github.com/openzipkin/zipkin-go/middleware/http"
一、broker-service
- 通过 Http 传递 span
main.go
package main
import (
"log"
"net/http"
zipkinhttp "github.com/openzipkin/zipkin-go/middleware/http"
)
type Config struct{
}
const (
// Our service name.
serviceName = "auth"
// Host + port of our service.
hostPort = "localhost:8090"
// Endpoint to send Zipkin spans to.
zipkinHTTPEndpoint = "http://localhost:9411/api/v2/spans"
)
func main() {
tracer := GetTracer(serviceName, hostPort, zipkinHTTPEndpoint)
// create global zipkin http server middleware
serverMiddleware := zipkinhttp.NewServerMiddleware(
tracer, zipkinhttp.TagResponseSize(true),
)
// create global zipkin traced http client
client, err := zipkinhttp.NewClient(tracer, zipkinhttp.ClientTrace(true))