Skip to content

Commit

Permalink
Set global tracer
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
Yuri Shkuro committed Sep 5, 2018
1 parent c4b02c8 commit d2935ff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 8 additions & 1 deletion cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
"syscall"

"github.com/gorilla/handlers"
"github.com/opentracing/opentracing-go"
"github.com/spf13/cobra"
"github.com/spf13/viper"
jaegerClientConfig "github.com/uber/jaeger-client-go/config"
jaegerClientZapLog "github.com/uber/jaeger-client-go/log/zap"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/env"
Expand Down Expand Up @@ -86,11 +88,16 @@ func main() {
Param: 1.0,
},
RPCMetrics: true,
}.New("jaeger-query", jaegerClientConfig.Metrics(baseFactory.Namespace("client", nil)))
}.New(
"jaeger-query",
jaegerClientConfig.Metrics(baseFactory.Namespace("client", nil)),
jaegerClientConfig.Logger(jaegerClientZapLog.NewLogger(logger)),
)
if err != nil {
logger.Fatal("Failed to initialize tracer", zap.Error(err))
}
defer closer.Close()
opentracing.SetGlobalTracer(tracer)

storageFactory.InitFromViper(v)
if err := storageFactory.Initialize(baseFactory, logger); err != nil {
Expand Down
10 changes: 9 additions & 1 deletion cmd/standalone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ import (
"syscall"

"github.com/gorilla/mux"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
jaegerClientConfig "github.com/uber/jaeger-client-go/config"
jaegerClientZapLog "github.com/uber/jaeger-client-go/log/zap"
"github.com/uber/jaeger-lib/metrics"
"github.com/uber/tchannel-go"
"github.com/uber/tchannel-go/thrift"
Expand Down Expand Up @@ -277,10 +279,16 @@ func startQuery(
Param: 1.0,
},
RPCMetrics: true,
}.New("jaeger-query", jaegerClientConfig.Metrics(baseFactory.Namespace("client", nil)))
}.New(
"jaeger-query",
jaegerClientConfig.Metrics(baseFactory.Namespace("client", nil)),
jaegerClientConfig.Logger(jaegerClientZapLog.NewLogger(logger)),
)
if err != nil {
logger.Fatal("Failed to initialize tracer", zap.Error(err))
}
opentracing.SetGlobalTracer(tracer)

apiHandler := queryApp.NewAPIHandler(
spanReader,
depReader,
Expand Down
9 changes: 8 additions & 1 deletion plugin/storage/cassandra/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,17 @@ func (s *SpanReader) GetOperations(ctx context.Context, service string) ([]strin
return s.operationNamesReader(service)
}

func lazyLogTraceID(traceID dbmodel.TraceID) func(fv otlog.Encoder) {
// unfortunately, this requires an allocation, due to the way OT API is defined.
return func(fv otlog.Encoder) {
fv.EmitObject("trace_id", traceID)
}
}

func (s *SpanReader) readTrace(ctx context.Context, traceID dbmodel.TraceID) (*model.Trace, error) {
span, ctx := startSpanForQuery(ctx, "readTrace", querySpanByTraceID)
defer span.Finish()
span.SetTag("traceID", traceID)
span.LogFields(otlog.String("event", "searching"), otlog.Lazy(lazyLogTraceID(traceID)))

trace, err := s.readTraceInSpan(ctx, traceID)
logErrorToSpan(span, err)
Expand Down

0 comments on commit d2935ff

Please sign in to comment.