Commit a234e894 by bergquist

makes jaeger tracing configurable

parent f160ad3b
......@@ -452,6 +452,11 @@ url = https://grafana.com
[grafana_com]
url = https://grafana.com
#################################### Distributed tracing ############
[tracing.jaeger]
# jaeger destination (ex localhost:5775)
address =
#################################### External Image Storage ##############
[external_image_storage]
# You can choose between (s3, webdav, gcs)
......
......@@ -391,6 +391,11 @@
;address =
;prefix = prod.grafana.%(instance_name)s.
#################################### Distributed tracing ############
[tracing.jaeger]
# Enable by setting the address sending traces to jaeger (ex localhost:5775)
;address = localhost:5775
#################################### Grafana.com integration ##########################
# Url used to to import dashboards directly from Grafana.com
[grafana_com]
......
......@@ -24,10 +24,7 @@ import (
"github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/social"
opentracing "github.com/opentracing/opentracing-go"
jaeger "github.com/uber/jaeger-client-go"
jaegercfg "github.com/uber/jaeger-client-go/config"
jaegerlog "github.com/uber/jaeger-client-go/log"
"github.com/grafana/grafana/pkg/tracing"
)
func NewGrafanaServer() models.GrafanaServer {
......@@ -65,33 +62,12 @@ func (g *GrafanaServerImpl) Start() {
eventpublisher.Init()
plugins.Init()
//localhost:5775
cfg := jaegercfg.Configuration{
Disabled: false,
Sampler: &jaegercfg.SamplerConfig{
Type: jaeger.SamplerTypeConst,
Param: 1,
},
Reporter: &jaegercfg.ReporterConfig{
LogSpans: false,
LocalAgentHostPort: "localhost:5775",
},
}
jLogger := jaegerlog.StdLogger
tracer, closer, err := cfg.New(
"grafana",
jaegercfg.Logger(jLogger),
)
closer, err := tracing.Init(setting.Cfg)
if err != nil {
g.log.Error("tracing", "error", err)
g.log.Error("Tracing settings is not valid", "error", err)
g.Shutdown(1, "Startup failed")
return
}
opentracing.InitGlobalTracer(tracer)
defer closer.Close()
// init alerting
......@@ -104,7 +80,7 @@ func (g *GrafanaServerImpl) Start() {
cleanUpService := cleanup.NewCleanUpService()
g.childRoutines.Go(func() error { return cleanUpService.Run(g.context) })
if err := notifications.Init(); err != nil {
if err = notifications.Init(); err != nil {
g.log.Error("Notification service failed to initialize", "error", err)
g.Shutdown(1, "Startup failed")
return
......
package tracing
import (
"io"
"io/ioutil"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/setting"
opentracing "github.com/opentracing/opentracing-go"
jaeger "github.com/uber/jaeger-client-go"
jaegercfg "github.com/uber/jaeger-client-go/config"
jaegerlog "github.com/uber/jaeger-client-go/log"
ini "gopkg.in/ini.v1"
)
var (
logger log.Logger = log.New("tracing")
)
type TracingSettings struct {
Enabled bool
Address string
}
func Init(file *ini.File) (io.Closer, error) {
settings := parseSettings(file)
return internalInit(settings)
}
func parseSettings(file *ini.File) *TracingSettings {
settings := &TracingSettings{}
var section, err = setting.Cfg.GetSection("tracing.jaeger")
if err != nil {
return settings
}
settings.Address = section.Key("address").MustString("")
if settings.Address != "" {
settings.Enabled = true
}
return settings
}
func internalInit(settings *TracingSettings) (io.Closer, error) {
if !settings.Enabled {
return ioutil.NopCloser(nil), nil
}
cfg := jaegercfg.Configuration{
Disabled: !settings.Enabled,
Sampler: &jaegercfg.SamplerConfig{
Type: jaeger.SamplerTypeConst,
Param: 1,
},
Reporter: &jaegercfg.ReporterConfig{
LogSpans: false,
LocalAgentHostPort: settings.Address,
},
}
jLogger := jaegerlog.StdLogger
tracer, closer, err := cfg.New(
"grafana",
jaegercfg.Logger(jLogger),
)
if err != nil {
return nil, err
}
logger.Info("Initialized jaeger tracer", "address", settings.Address)
opentracing.InitGlobalTracer(tracer)
return closer, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment