Add support for tracing via OpenCencus

This adds a few flags for configuring the tracer.
Includes support for jaeger tracing (built into OC).
This commit is contained in:
Brian Goff
2018-09-19 18:01:39 -07:00
parent 43d32d2301
commit 682b2bccf8
139 changed files with 19834 additions and 42 deletions

51
cmd/census.go Normal file
View File

@@ -0,0 +1,51 @@
package cmd
import (
"github.com/pkg/errors"
"go.opencensus.io/trace"
)
var (
tracingExporters = make(map[string]TracingExporterInitFunc)
reservedTagNames = map[string]bool{
"operatingSystem": true,
"provider": true,
"nodeName": true,
}
)
// TracingExporterOptions is used to pass options to the configured tracer
type TracingExporterOptions struct {
Tags map[string]string
ServiceName string
}
// TracingExporterInitFunc is the function that is called to initialize an exporter.
// This is used when registering an exporter and called when a user specifed they want to use the exporter.
type TracingExporterInitFunc func(TracingExporterOptions) (trace.Exporter, error)
// RegisterTracingExporter registers a tracing exporter.
// For a user to select an exporter, it must be registered here.
func RegisterTracingExporter(name string, f TracingExporterInitFunc) {
tracingExporters[name] = f
}
// GetTracingExporter gets the specified tracing exporter passing in the options to the exporter init function.
// For an exporter to be availbale here it must be registered with `RegisterTracingExporter`.
func GetTracingExporter(name string, opts TracingExporterOptions) (trace.Exporter, error) {
f, ok := tracingExporters[name]
if !ok {
return nil, errors.Errorf("tracing exporter %q not found", name)
}
return f(opts)
}
// AvailableTraceExporters gets the list of registered exporters
func AvailableTraceExporters() []string {
out := make([]string, 0, len(tracingExporters))
for k := range tracingExporters {
out = append(out, k)
}
return out
}