fix jaeger deprecated config

This commit is contained in:
champly
2021-05-12 10:36:58 +08:00
parent baa0e6e8fc
commit 0df7ac4e80

View File

@@ -18,6 +18,7 @@ package root
import ( import (
"errors" "errors"
"fmt"
"os" "os"
"contrib.go.opencensus.io/exporter/jaeger" "contrib.go.opencensus.io/exporter/jaeger"
@@ -31,17 +32,21 @@ func init() {
// NewJaegerExporter creates a new opencensus tracing exporter. // NewJaegerExporter creates a new opencensus tracing exporter.
func NewJaegerExporter(opts TracingExporterOptions) (trace.Exporter, error) { func NewJaegerExporter(opts TracingExporterOptions) (trace.Exporter, error) {
jOpts := jaeger.Options{ jOpts := jaeger.Options{
Endpoint: os.Getenv("JAEGER_ENDPOINT"), Endpoint: os.Getenv("JAEGER_ENDPOINT"), // deprecated
AgentEndpoint: os.Getenv("JAEGER_AGENT_ENDPOINT"), CollectorEndpoint: os.Getenv("JAEGER_COLLECTOR_ENDPOINT"),
Username: os.Getenv("JAEGER_USER"), AgentEndpoint: os.Getenv("JAEGER_AGENT_ENDPOINT"),
Password: os.Getenv("JAEGER_PASSWORD"), Username: os.Getenv("JAEGER_USER"),
Password: os.Getenv("JAEGER_PASSWORD"),
Process: jaeger.Process{ Process: jaeger.Process{
ServiceName: opts.ServiceName, ServiceName: opts.ServiceName,
}, },
} }
if jOpts.Endpoint == "" && jOpts.AgentEndpoint == "" { // nolint:staticcheck if jOpts.Endpoint != "" && jOpts.CollectorEndpoint == "" {
return nil, errors.New("Must specify either JAEGER_ENDPOINT or JAEGER_AGENT_ENDPOINT") jOpts.CollectorEndpoint = fmt.Sprintf("%s/api/traces", jOpts.Endpoint)
}
if jOpts.CollectorEndpoint == "" && jOpts.AgentEndpoint == "" { // nolint:staticcheck
return nil, errors.New("Must specify either JAEGER_COLLECTOR_ENDPOINT or JAEGER_AGENT_ENDPOINT")
} }
for k, v := range opts.Tags { for k, v := range opts.Tags {