Commit ec29b469 by bergquist

adds custom tags from settings

parent e3211f6e
......@@ -456,6 +456,8 @@ url = https://grafana.com
[tracing.jaeger]
# jaeger destination (ex localhost:6831)
address =
# tag that will always be included in when creating new spans. ex (tag1:value1,tag2:value2)
always_included_tag =
#################################### External Image Storage ##############
[external_image_storage]
......
......@@ -395,6 +395,8 @@
[tracing.jaeger]
# Enable by setting the address sending traces to jaeger (ex localhost:6831)
;address = localhost:6831
# Tag that will always be included in when creating new spans. ex (tag1:value1,tag2:value2)
;always_included_tag = tag1:value1
#################################### Grafana.com integration ##########################
# Url used to to import dashboards directly from Grafana.com
......
......@@ -14,11 +14,9 @@ func RequestTracing(handler string) macaron.Handler {
return func(res http.ResponseWriter, req *http.Request, c *macaron.Context) {
rw := res.(macaron.ResponseWriter)
var span opentracing.Span
tracer := opentracing.GlobalTracer()
wireContext, _ := tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(req.Header))
spanName := fmt.Sprintf("HTTP %s", handler)
span = tracer.StartSpan(spanName, ext.RPCServerOption(wireContext))
span := tracer.StartSpan(fmt.Sprintf("HTTP %s", handler), ext.RPCServerOption(wireContext))
defer span.Finish()
ctx := opentracing.ContextWithSpan(req.Context(), span)
......
......@@ -3,6 +3,7 @@ package tracing
import (
"io"
"io/ioutil"
"strings"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/setting"
......@@ -15,7 +16,8 @@ import (
)
var (
logger log.Logger = log.New("tracing")
logger log.Logger = log.New("tracing")
customTags map[string]string = map[string]string{}
)
type TracingSettings struct {
......@@ -41,6 +43,8 @@ func parseSettings(file *ini.File) *TracingSettings {
settings.Enabled = true
}
customTags = splitTagSettings(section.Key("always_included_tag").MustString(""))
return settings
}
......@@ -63,10 +67,14 @@ func internalInit(settings *TracingSettings) (io.Closer, error) {
jLogger := jaegerlog.StdLogger
tracer, closer, err := cfg.New(
"grafana",
jaegercfg.Logger(jLogger),
)
options := []jaegercfg.Option{}
options = append(options, jaegercfg.Logger(jLogger))
for tag, value := range customTags {
options = append(options, jaegercfg.Tag(tag, value))
}
tracer, closer, err := cfg.New("grafana", options...)
if err != nil {
return nil, err
}
......@@ -75,3 +83,17 @@ func internalInit(settings *TracingSettings) (io.Closer, error) {
opentracing.InitGlobalTracer(tracer)
return closer, nil
}
func splitTagSettings(input string) map[string]string {
res := map[string]string{}
tags := strings.Split(input, ",")
for _, v := range tags {
kv := strings.Split(v, ":")
if len(kv) > 1 {
res[kv[0]] = kv[1]
}
}
return res
}
package tracing
import "testing"
func TestGroupSplit(t *testing.T) {
tests := []struct {
input string
expected map[string]string
}{
{
input: "tag1:value1,tag2:value2",
expected: map[string]string{
"tag1": "value1",
"tag2": "value2",
},
},
{
input: "",
expected: map[string]string{},
},
{
input: "tag1",
expected: map[string]string{},
},
}
for _, test := range tests {
tags := splitTagSettings(test.input)
for k, v := range test.expected {
value, exists := tags[k]
if !exists || value != v {
t.Errorf("tags does not match %v ", test)
}
}
}
}
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