Signed-off-by: Andres Taylor <antaylor@squareup.com>
This commit is contained in:
Andres Taylor 2019-04-12 11:04:53 +02:00
Родитель b3345fd2c3
Коммит 459756c74d
3 изменённых файлов: 14 добавлений и 13 удалений

Просмотреть файл

@ -27,7 +27,6 @@ import (
"golang.org/x/net/context"
"google.golang.org/grpc"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vterrors"
)
@ -132,21 +131,14 @@ var tracingBackendFactories = make(map[string]TracerFactory)
var spanFactory TracingService = fakeSpanFactory{}
var (
tracingServer = flag.String("tracer", "noop", "tracing service to use.")
tracingServer = flag.String("tracer", "noop", "tracing service to use")
)
// StartTracing enables tracing for a named service
func StartTracing(serviceName string) io.Closer {
factory, ok := tracingBackendFactories[*tracingServer]
if !ok {
options := make([]string, len(tracingBackendFactories))
for k := range tracingBackendFactories {
options = append(options, k)
}
altStr := strings.Join(options, ", ")
log.Error(vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "no such tracing service found. alternatives are: %v", altStr))
return &nilCloser{}
return fail(serviceName)
}
tracer, closer, err := factory(serviceName)
@ -159,3 +151,13 @@ func StartTracing(serviceName string) io.Closer {
return closer
}
func fail(serviceName string) io.Closer {
options := make([]string, len(tracingBackendFactories))
for k := range tracingBackendFactories {
options = append(options, k)
}
altStr := strings.Join(options, ", ")
log.Errorf("no such [%s] tracing service found. alternatives are: %v", serviceName, altStr)
return &nilCloser{}
}

Просмотреть файл

@ -128,6 +128,7 @@ func (f *fakeTracer) Close() error {
}
func (f *fakeTracer) assertNoSpanWith(t *testing.T, substr string) {
t.Helper()
for _, logLine := range f.log {
if strings.Contains(logLine, substr) {
t.Fatalf("expected to not find [%v] but found it in [%v]", substr, logLine)
@ -146,5 +147,3 @@ func (m *mockSpan) Finish() {
func (m *mockSpan) Annotate(key string, value interface{}) {
m.tracer.log = append(m.tracer.log, fmt.Sprintf("key: %v values:%v", key, value))
}

Просмотреть файл

@ -131,7 +131,7 @@ func (wi *Instance) setAndStartWorker(ctx context.Context, wrk Worker, wr *wrang
go func() {
log.Infof("Starting worker...")
span, ctx := trace.NewSpan(wi.currentContext, "work")
span.Annotate("extra", wrk.StatusAsText())
span.Annotate("extra", wrk.State().String())
defer span.Finish()
var err error