Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trace] Add logging support to opentracing plugins #8289

Merged
merged 2 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions go/cmd/vtadmin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ func main() {
rootCmd.Flags().Var(&clusterFileConfig, "cluster-config", "path to a yaml cluster configuration. see clusters.example.yaml") // (TODO:@amason) provide example config.
rootCmd.Flags().Var(&defaultClusterConfig, "cluster-defaults", "default options for all clusters")

rootCmd.Flags().AddGoFlag(flag.Lookup("tracer")) // defined in go/vt/trace
rootCmd.Flags().AddGoFlag(flag.Lookup("tracing-sampling-type")) // defined in go/vt/trace
rootCmd.Flags().AddGoFlag(flag.Lookup("tracing-sampling-rate")) // defined in go/vt/trace
rootCmd.Flags().AddGoFlag(flag.Lookup("tracer")) // defined in go/vt/trace
rootCmd.Flags().AddGoFlag(flag.Lookup("tracing-enable-logging")) // defined in go/vt/trace
rootCmd.Flags().AddGoFlag(flag.Lookup("tracing-sampling-type")) // defined in go/vt/trace
rootCmd.Flags().AddGoFlag(flag.Lookup("tracing-sampling-rate")) // defined in go/vt/trace
rootCmd.Flags().BoolVar(&opts.EnableTracing, "grpc-tracing", false, "whether to enable tracing on the gRPC server")
rootCmd.Flags().BoolVar(&httpOpts.EnableTracing, "http-tracing", false, "whether to enable tracing on the HTTP server")

Expand Down
32 changes: 32 additions & 0 deletions go/trace/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2021 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package trace

import "vitess.io/vitess/go/vt/log"

// traceLogger wraps the standard vitess log package to satisfy the datadog and
// jaeger logger interfaces.
type traceLogger struct{}

// Log is part of the ddtrace.Logger interface. Datadog only ever logs errors.
func (*traceLogger) Log(msg string) { log.Errorf(msg) }

// Error is part of the jaeger.Logger interface.
func (*traceLogger) Error(msg string) { log.Errorf(msg) }

// Infof is part of the jaeger.Logger interface.
func (*traceLogger) Infof(msg string, args ...interface{}) { log.Infof(msg, args...) }
12 changes: 9 additions & 3 deletions go/trace/plugin_datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ func newDatadogTracer(serviceName string) (tracingService, io.Closer, error) {
return nil, nil, fmt.Errorf("need host and port to datadog agent to use datadog tracing")
}

t := opentracer.New(
ddtracer.WithAgentAddr(*dataDogHost+":"+*dataDogPort),
opts := []ddtracer.StartOption{
ddtracer.WithAgentAddr(*dataDogHost + ":" + *dataDogPort),
ddtracer.WithServiceName(serviceName),
ddtracer.WithDebugMode(true),
ddtracer.WithSampler(ddtracer.NewRateSampler(samplingRate.Get())),
)
}

if *enableLogging {
opts = append(opts, ddtracer.WithLogger(&traceLogger{}))
}

t := opentracer.New(opts...)

opentracing.SetGlobalTracer(t)

Expand Down
9 changes: 8 additions & 1 deletion go/trace/plugin_jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ func newJagerTracerFromEnv(serviceName string) (tracingService, io.Closer, error

log.Infof("Tracing sampler type %v (param: %v)", cfg.Sampler.Type, cfg.Sampler.Param)

tracer, closer, err := cfg.NewTracer()
var opts []config.Option
if *enableLogging {
opts = append(opts, config.Logger(&traceLogger{}))
} else if cfg.Reporter.LogSpans {
log.Warningf("JAEGER_REPORTER_LOG_SPANS was set, but -tracing-enable-logging was not; spans will not be logged")
}

tracer, closer, err := cfg.NewTracer(opts...)

if err != nil {
return nil, &nilCloser{}, err
Expand Down
1 change: 1 addition & 0 deletions go/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ var currentTracer tracingService = noopTracingServer{}

var (
tracingServer = flag.String("tracer", "noop", "tracing service to use")
enableLogging = flag.Bool("tracing-enable-logging", false, "whether to enable logging in the tracing service")
)

// StartTracing enables tracing for a named service
Expand Down