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

separate tracing environment variables #6323

Merged
merged 3 commits into from
May 26, 2021
Merged
Changes from 1 commit
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
61 changes: 53 additions & 8 deletions lib/tracing/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tracing

import (
"os"
"strings"

"contrib.go.opencensus.io/exporter/jaeger"
logging "github.com/ipfs/go-log/v2"
Expand All @@ -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 {
return nil
// 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
}
agentEndpointURI := os.Getenv("LOTUS_JAEGER")
log.Infof("jaeger tracing is not configured.")
return false
}

je, err := jaeger.NewExporter(jaeger.Options{
AgentEndpoint: agentEndpointURI,
ServiceName: serviceName,
})
func SetupJaegerTracing(serviceName string) *jaeger.Exporter {
opts := jaeger.Options{}
if !jaegerOptsFromEnv(&opts) {
return nil
}
opts.ServiceName = serviceName
je, err := jaeger.NewExporter(opts)
if err != nil {
log.Errorw("Failed to create the Jaeger exporter", "error", err)
return nil
Expand Down