Commit 4e75d592 authored by ale's avatar ale

Tracing: make sampling frequency configurable

parent 1f95fcdd
......@@ -8,6 +8,7 @@ import (
"net/http"
"os"
"path/filepath"
"strconv"
"sync"
openzipkin "github.com/openzipkin/zipkin-go"
......@@ -31,6 +32,7 @@ const globalTracingConfigPath = "/etc/tracing/client.conf"
type tracingConfig struct {
ReportURL string `json:"report_url"`
Sample string `json:"sample"`
}
// Read the global tracing configuration file. Its location is
......@@ -100,9 +102,23 @@ func initTracing(endpointAddr string) {
reporter := zipkinHTTP.NewReporter(config.ReportURL)
ze := zipkin.NewExporter(reporter, localEndpoint)
trace.RegisterExporter(ze)
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
var tc trace.Config
switch config.Sample {
case "", "always":
tc.DefaultSampler = trace.AlwaysSample()
case "never":
tc.DefaultSampler = trace.NeverSample()
default:
frac, err := strconv.ParseFloat(config.Sample, 64)
if err != nil {
log.Printf("warning: error in tracing configuration: sample: %v, tracing disabled", err)
return
}
tc.DefaultSampler = trace.ProbabilitySampler(frac)
}
trace.ApplyConfig(tc)
log.Printf("tracing enabled (report_url %s)", config.ReportURL)
......
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