Skip to content

Commit

Permalink
cmd/query: init tracer config from env
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Saltykov <alexander-s@yandex-team.ru>
  • Loading branch information
holycheater committed Sep 14, 2019
1 parent 3fa1dfa commit 14b57fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
25 changes: 25 additions & 0 deletions cmd/query/app/tracing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package app

import (
"os"

jaegerClientConfig "github.com/uber/jaeger-client-go/config"
)

func TracerConfig() (*jaegerClientConfig.Configuration, error) {
cfg, err := jaegerClientConfig.FromEnv()
if err != nil {
return nil, err
}
// backwards compatibility
if e := os.Getenv("JAEGER_RPC_METRICS"); e == "" {
cfg.RPCMetrics = true
}
if e := os.Getenv("JAEGER_SAMPLER_TYPE"); e == "" {
cfg.Sampler.Type = "probabilistic"
}
if e := os.Getenv("JAEGER_SAMPLER_PARAM"); e == "" {
cfg.Sampler.Param = 1.0
}
return cfg, nil
}
16 changes: 6 additions & 10 deletions cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,18 @@ func main() {
baseFactory := svc.MetricsFactory.Namespace(metrics.NSOptions{Name: "jaeger"})
metricsFactory := baseFactory.Namespace(metrics.NSOptions{Name: "query"})

tracer, closer, err := jaegerClientConfig.Configuration{
ServiceName: "jaeger-query",
Sampler: &jaegerClientConfig.SamplerConfig{
Type: "probabilistic",
Param: 1.0,
},
RPCMetrics: true,
}.NewTracer(
cfg, err := app.TracerConfig()
if err != nil {
logger.Fatal("Failed to read tracer config from env", zap.Error(err))
}
closer, err := cfg.InitGlobalTracer("jaeger-query",
jaegerClientConfig.Metrics(svc.MetricsFactory),
jaegerClientConfig.Logger(jaegerClientZapLog.NewLogger(logger)),
)
if err != nil {
logger.Fatal("Failed to initialize tracer", zap.Error(err))
}
defer closer.Close()
opentracing.SetGlobalTracer(tracer)
queryOpts := new(app.QueryOptions).InitFromViper(v)
// TODO: Need to figure out set enable/disable propagation on storage plugins.
v.Set(spanstore.StoragePropagationKey, queryOpts.BearerTokenPropagation)
Expand All @@ -102,7 +98,7 @@ func main() {
dependencyReader,
*queryServiceOptions)

server := app.NewServer(svc, queryService, queryOpts, tracer)
server := app.NewServer(svc, queryService, queryOpts, opentracing.GlobalTracer())

if err := server.Start(); err != nil {
logger.Fatal("Could not start servers", zap.Error(err))
Expand Down

0 comments on commit 14b57fa

Please sign in to comment.