separate tracing environment variables
This commit is contained in:
parent
d3ad897fe9
commit
273368ed6a
@ -2,6 +2,7 @@ package tracing
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"contrib.go.opencensus.io/exporter/jaeger"
|
||||
logging "github.com/ipfs/go-log/v2"
|
||||
@ -10,17 +11,61 @@ import (
|
||||
|
||||
var log = logging.Logger("tracing")
|
||||
|
||||
func SetupJaegerTracing(serviceName string) *jaeger.Exporter {
|
||||
const (
|
||||
// environment variable names
|
||||
envCollectorEndpoint = "LOTUS_JAEGER_COLLECTOR_ENDPOINT"
|
||||
envAgentEndpoint = "LOTUS_JAEGER_AGENT_ENDPOINT"
|
||||
envAgentHost = "LOTUS_JAEGER_AGENT_HOST"
|
||||
envAgentPort = "LOTUS_JAEGER_AGENT_PORT"
|
||||
envUsername = "LOTUS_JAEGER_USERNAME"
|
||||
envPassword = "LOTUS_JAEGER_PASSWORD"
|
||||
)
|
||||
|
||||
if _, ok := os.LookupEnv("LOTUS_JAEGER"); !ok {
|
||||
// When sending directly to the collector, agent options are ignored.
|
||||
// The collector endpoint is an HTTP or HTTPs URL.
|
||||
// The agent endpoint is a thrift/udp protocol given like "hostname:port"
|
||||
// or separate host and port environment variables.
|
||||
func jaegerOptsFromEnv(opts *jaeger.Options) bool {
|
||||
var e string
|
||||
var ok bool
|
||||
if e, ok = os.LookupEnv(envUsername); ok {
|
||||
if p, ok := os.LookupEnv(envPassword); ok {
|
||||
opts.Username = e
|
||||
opts.Password = p
|
||||
} else {
|
||||
log.Warn("jaeger username supplied with no password. authentication will not be used.")
|
||||
}
|
||||
}
|
||||
if e, ok = os.LookupEnv(envCollectorEndpoint); ok {
|
||||
opts.CollectorEndpoint = e
|
||||
log.Infof("jaeger tracess will send to collector %s", e)
|
||||
return true
|
||||
}
|
||||
if e, ok = os.LookupEnv(envAgentEndpoint); ok {
|
||||
log.Infof("jaeger traces will be sent to agent %s", e)
|
||||
opts.AgentEndpoint = e
|
||||
return true
|
||||
}
|
||||
if e, ok = os.LookupEnv(envAgentHost); ok {
|
||||
if p, ok := os.LookupEnv(envAgentPort); ok {
|
||||
opts.AgentEndpoint = strings.Join([]string{e, p}, ":")
|
||||
} else {
|
||||
opts.AgentEndpoint = strings.Join([]string{e, "6831"}, ":")
|
||||
}
|
||||
log.Infof("jaeger traces will be sent to agent %s", opts.AgentEndpoint)
|
||||
return true
|
||||
}
|
||||
log.Infof("jaeger tracing is not configured.")
|
||||
return false
|
||||
}
|
||||
|
||||
func SetupJaegerTracing(serviceName string) *jaeger.Exporter {
|
||||
opts := jaeger.Options{}
|
||||
if !jaegerOptsFromEnv(&opts) {
|
||||
return nil
|
||||
}
|
||||
agentEndpointURI := os.Getenv("LOTUS_JAEGER")
|
||||
|
||||
je, err := jaeger.NewExporter(jaeger.Options{
|
||||
AgentEndpoint: agentEndpointURI,
|
||||
ServiceName: serviceName,
|
||||
})
|
||||
opts.ServiceName = serviceName
|
||||
je, err := jaeger.NewExporter(opts)
|
||||
if err != nil {
|
||||
log.Errorw("Failed to create the Jaeger exporter", "error", err)
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user