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:
51
cmd/census.go
Normal file
51
cmd/census.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user