-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.go
65 lines (52 loc) · 1.45 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"os"
"log"
"github.com/micro/go-grpc"
"github.com/micro/go-micro"
"github.com/micro/go-micro/registry/consul"
"github.com/micro/go-micro/registry"
opentracing "github.com/opentracing/opentracing-go"
zipkin "github.com/openzipkin/zipkin-go-opentracing"
"github.com/henter/go-zipkin-demo/pb"
"github.com/henter/go-zipkin-demo/handler"
"github.com/henter/go-zipkin-demo/trace"
)
func main() {
service_name := "go.zipkin.demo"
zipkin_addr := "http://localhost:9411/api/v1/spans"
consul_addr := "127.0.0.1:8500"
hostname, _ := os.Hostname()
InitTracer(zipkin_addr, hostname, service_name)
reg := consul.NewRegistry(
registry.Addrs(consul_addr),
)
service := grpc.NewService(
micro.Name(service_name),
micro.Version("v0.1"),
micro.Registry(reg),
micro.WrapHandler(trace.ServerWrapper),
)
service.Init()
pb.RegisterDemoHandler(service.Server(), new(handler.Demo))
// Run server
if err := service.Run(); err != nil {
log.Fatalf("service error: %s", err.Error())
}
}
func InitTracer(zipkinURL string, hostPort string, serviceName string) {
collector, err := zipkin.NewHTTPCollector(zipkinURL)
if err != nil {
log.Fatalf("unable to create Zipkin HTTP collector: %v", err)
return
}
tracer, err := zipkin.NewTracer(
zipkin.NewRecorder(collector, false, hostPort, serviceName),
)
if err != nil {
log.Fatalf("unable to create Zipkin tracer: %v", err)
return
}
opentracing.InitGlobalTracer(tracer)
return
}