mirror of
https://github.com/grafana/grafana.git
synced 2026-08-14 15:15:03 -05:00
adds custom tags from settings
This commit is contained in:
+27
-5
@@ -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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user