Zipkin : Golang 微服务全链路监控(三)

Zipkin : Golang 微服务全链路监控(三)

Golang 微服务全链路监控实现

  1. broker-service -> auth-service -> postgres db
  2. zipkin 监控:需代码入侵

使用 zipkin 库的 serverMiddleware,其通过 Http 跟踪(trace)链路。若要连接数据库,需传 tracer

zipkinhttp "github.com/openzipkin/zipkin-go/middleware/http"

一、auth-service

  1. 通过 Http 传递 span
    main.go
package main

import (
	"database/sql"
	"log"
	"net/http"
	"os"
	"time"
	"tracing/auth-service/data"

	zipkinhttp "github.com/openzipkin/zipkin-go/middleware/http"

	_ "github.com/jackc/pgconn"
	_ "github.com/jackc/pgx/v4"
	_ "github.com/jackc/pgx/v4/stdlib"
)

const webPort = "80"

const (
	// Our service name.
	serviceName = "authentication"

	// Host + port of our service.
	hostPort = "localhost:8090"

	// Endpoint to send Zipkin spans to.
	zipkinHTTPEndpoint = "http://localhost:9411/api/v2/spans"
)

var counts int64

type Config struct {
   
	DB     *sql.DB
	Models data.Models
}

func main() {
   
	log.Println("Starting authentication service: ", webPort)

	//connect to DB
	conn := connectToDB()
	if conn == nil {
   
		log.Panic("Can't connect to Postgres!")
	}

	//setup config
	app := Config{
   
		DB:     conn,
		Models: data.New(conn),
	}

	tracer := GetTracer(serviceName, hostPort, zipkinHTTPEndpoint)

	// create global zipkin http server middleware
	serverMiddleware := zipkinhttp
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值