-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.go
66 lines (53 loc) · 1.93 KB
/
setup.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
64
65
66
package main
import (
"io"
"log"
"github.com/devit-tel/goxid"
"github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"
jaegercfg "github.com/uber/jaeger-client-go/config"
jaegerlog "github.com/uber/jaeger-client-go/log"
"github.com/uber/jaeger-lib/metrics"
"github.com/devit-tel/gogo-blueprint/app"
"github.com/devit-tel/gogo-blueprint/config"
companyRepo "github.com/devit-tel/gogo-blueprint/repository/company/store"
staffRepo "github.com/devit-tel/gogo-blueprint/repository/staff/store"
companyService "github.com/devit-tel/gogo-blueprint/service/company"
companyServiceTracer "github.com/devit-tel/gogo-blueprint/service/company/withtracer"
staffService "github.com/devit-tel/gogo-blueprint/service/staff"
staffServiceTracer "github.com/devit-tel/gogo-blueprint/service/staff/withtracer"
)
func setupJaeger(appConfig *config.Config) io.Closer {
cfg, err := jaegercfg.FromEnv()
if err != nil {
log.Panic(err)
}
cfg.ServiceName = appConfig.AppName
cfg.Sampler.Type = "const"
cfg.Sampler.Param = 1
cfg.Reporter = &jaegercfg.ReporterConfig{LogSpans: true}
jLogger := jaegerlog.StdLogger
jMetricsFactory := metrics.NullFactory
tracer, closer, err := cfg.NewTracer(
jaegercfg.Logger(jLogger),
jaegercfg.Metrics(jMetricsFactory),
)
if err != nil {
log.Panic(err)
}
opentracing.SetGlobalTracer(tracer)
return closer
}
func newApp(appConfig *config.Config) *app.App {
xid := goxid.New()
companyStore := companyRepo.New(appConfig.MongoDBEndpoint, appConfig.MongoDBName, appConfig.MongoDBCompanyTableName)
company := companyServiceTracer.Wrap(companyService.New(xid, companyStore))
staffStore := staffRepo.New(appConfig.MongoDBEndpoint, appConfig.MongoDBName, appConfig.MongoDBStaffTableName)
staff := staffServiceTracer.Wrap(staffService.New(xid, staffStore, companyStore))
return app.New(staff, company)
}
func setupLog() *logrus.Logger {
lr := logrus.New()
lr.SetFormatter(&logrus.JSONFormatter{})
return lr
}