Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

support adding arbitrary extra tags in jaeger traces #904

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/mt-store-cat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func main() {
if err != nil {
log.Fatal(4, "failed to initialize cassandra. %s", err)
}
tracer, traceCloser, err := conf.GetTracer(false, "")
tracer, traceCloser, err := conf.GetTracer(false, "", nil)
if err != nil {
log.Fatal(4, "Could not initialize jaeger tracer: %s", err.Error())
}
Expand Down
13 changes: 11 additions & 2 deletions conf/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
jaegerlog "github.com/uber/jaeger-client-go/log"
)

func GetTracer(enabled bool, addr string) (opentracing.Tracer, io.Closer, error) {
// GetTracer returns a jaeger tracer
// any tags specified will be added as process/tracer-level tags
func GetTracer(enabled bool, addr string, tags map[string]string) (opentracing.Tracer, io.Closer, error) {
// Sample configuration for testing. Use constant sampling to sample every trace
// and enable LogSpan to log every span via configured Logger.
cfg := jaegercfg.Configuration{
Expand All @@ -26,9 +28,16 @@ func GetTracer(enabled bool, addr string) (opentracing.Tracer, io.Closer, error)

jLogger := jaegerlog.StdLogger

options := []jaegercfg.Option{
jaegercfg.Logger(jLogger),
}
for k, v := range tags {
options = append(options, jaegercfg.Tag(k, v))
}

tracer, closer, err := cfg.New(
"metrictank",
jaegercfg.Logger(jLogger),
options...,
)
if err != nil {
return nil, nil, err
Expand Down
2 changes: 2 additions & 0 deletions docker/docker-chaos/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ log-level = 2
tracing-enabled = true
# address of the jaeger agent to send data to
tracing-addr = jaeger:6831
# tracer/process-level tags to include, specified as comma-separated key:value pairs
tracing-add-tags =

## Retention settings ##
[retention]
Expand Down
2 changes: 2 additions & 0 deletions docker/docker-cluster/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ log-level = 2
tracing-enabled = true
# address of the jaeger agent to send data to
tracing-addr = jaeger:6831
# tracer/process-level tags to include, specified as comma-separated key:value pairs
tracing-add-tags =

## Retention settings ##
[retention]
Expand Down
2 changes: 2 additions & 0 deletions docker/docker-dev-custom-cfg-kafka/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ log-level = 2
tracing-enabled = false
# address of the jaeger agent to send data to
tracing-addr = localhost:6831
# tracer/process-level tags to include, specified as comma-separated key:value pairs
tracing-add-tags =

## Retention settings ##
[retention]
Expand Down
2 changes: 2 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ log-level = 2
tracing-enabled = false
# address of the jaeger agent to send data to
tracing-addr = localhost:6831
# tracer/process-level tags to include, specified as comma-separated key:value pairs
tracing-add-tags =
```

## Retention settings ##
Expand Down
2 changes: 2 additions & 0 deletions metrictank-sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ log-level = 2
tracing-enabled = false
# address of the jaeger agent to send data to
tracing-addr = localhost:6831
# tracer/process-level tags to include, specified as comma-separated key:value pairs
tracing-add-tags =

## Retention settings ##
[retention]
Expand Down
16 changes: 15 additions & 1 deletion metrictank.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ var (

tracingEnabled = flag.Bool("tracing-enabled", false, "enable/disable distributed opentracing via jaeger")
tracingAddr = flag.String("tracing-addr", "localhost:6831", "address of the jaeger agent to send data to")
tracingAddTags = flag.String("tracing-add-tags", "", "tracer/process-level tags to include, specified as comma-separated key:value pairs")
)

func init() {
Expand Down Expand Up @@ -270,7 +271,20 @@ func main() {
/***********************************
Initialize tracer
***********************************/
tracer, traceCloser, err := conf.GetTracer(*tracingEnabled, *tracingAddr)
*tracingAddTags = strings.TrimSpace(*tracingAddTags)
var tags map[string]string
if len(*tracingAddTags) > 0 {
tagSpecs := strings.Split(*tracingAddTags, ",")
tags = make(map[string]string)
for _, tagSpec := range tagSpecs {
split := strings.Split(tagSpec, ":")
if len(split) != 2 {
log.Fatal(4, "cannot parse tracing-add-tags value %q", tagSpec)
}
tags[split[0]] = split[1]
}
}
tracer, traceCloser, err := conf.GetTracer(*tracingEnabled, *tracingAddr, tags)
if err != nil {
log.Fatal(4, "Could not initialize jaeger tracer: %s", err.Error())
}
Expand Down
2 changes: 2 additions & 0 deletions scripts/config/metrictank-docker.ini
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ log-level = 2
tracing-enabled = false
# address of the jaeger agent to send data to
tracing-addr = localhost:6831
# tracer/process-level tags to include, specified as comma-separated key:value pairs
tracing-add-tags =

## Retention settings ##
[retention]
Expand Down
2 changes: 2 additions & 0 deletions scripts/config/metrictank-package.ini
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ log-level = 2
tracing-enabled = false
# address of the jaeger agent to send data to
tracing-addr = localhost:6831
# tracer/process-level tags to include, specified as comma-separated key:value pairs
tracing-add-tags =

## Retention settings ##
[retention]
Expand Down