diff --git a/cmd/proxy/actions/app.go b/cmd/proxy/actions/app.go index a5e84e21..31df6eaf 100644 --- a/cmd/proxy/actions/app.go +++ b/cmd/proxy/actions/app.go @@ -90,7 +90,7 @@ func App(conf *config.Config) (*buffalo.App, error) { } // Register exporter to export traces - exporter, err := observ.RegisterTraceExporter(Service, ENV) + exporter, err := observ.RegisterTraceExporter(conf.TraceExporterURL, Service, ENV) if err != nil { lggr.SystemErr(err) } else { diff --git a/config.example.toml b/config.example.toml index 1520ad17..be1c5986 100644 --- a/config.example.toml +++ b/config.example.toml @@ -69,7 +69,6 @@ Timeout = 300 # Env override: ATHENS_ENABLE_CSRF_PROTECTION EnableCSRFProtection = false - [Proxy] # StorageType sets the type of storage backend the proxy will use. # Possible values are memory, disk, mongo, gcp, minio @@ -128,6 +127,11 @@ EnableCSRFProtection = false # Env override: ATHENS_NETRC_PATH NETRCPath = "" + # TraceExporterURL is the URL to which Athens populates distributed tracing + # information such as Jaeger. + # Env override: ATHENS_TRACE_EXPORTER + TraceExporterURL = "" + [Olympus] # StorageType sets the type of storage backend Olympus will use. # Possible values are memory, disk, mongo, postgres, sqlite, cockroach, mysql diff --git a/pkg/config/env/trace.go b/pkg/config/env/trace.go deleted file mode 100644 index bea9c827..00000000 --- a/pkg/config/env/trace.go +++ /dev/null @@ -1,8 +0,0 @@ -package env - -import "os" - -// TraceExporterURL returns where the trace is stored to -func TraceExporterURL() string { - return os.Getenv("TRACE_EXPORTER") -} diff --git a/pkg/config/parse.go b/pkg/config/parse.go index dbf324b5..0d9907b8 100644 --- a/pkg/config/parse.go +++ b/pkg/config/parse.go @@ -25,6 +25,7 @@ type Config struct { CloudRuntime string `validate:"required" envconfig:"ATHENS_CLOUD_RUNTIME"` FilterFile string `envconfig:"ATHENS_FILTER_FILE"` EnableCSRFProtection bool `envconfig:"ATHENS_ENABLE_CSRF_PROTECTION"` + TraceExporterURL string `envconfig:"ATHENS_TRACE_EXPORTER"` Proxy *ProxyConfig Olympus *OlympusConfig `validate:"-"` // ignoring validation until Olympus is up. Storage *StorageConfig diff --git a/pkg/config/parse_test.go b/pkg/config/parse_test.go index dde1b50f..0e331a67 100644 --- a/pkg/config/parse_test.go +++ b/pkg/config/parse_test.go @@ -351,6 +351,7 @@ func getEnvMap(config *Config) map[string]string { "ATHENS_FILTER_FILE": config.FilterFile, "ATHENS_TIMEOUT": strconv.Itoa(config.Timeout), "ATHENS_ENABLE_CSRF_PROTECTION": strconv.FormatBool(config.EnableCSRFProtection), + "ATHENS_TRACE_EXPORTER": config.TraceExporterURL, } proxy := config.Proxy diff --git a/pkg/observ/tracing.go b/pkg/observ/tracing.go index 2955f922..3d253ef4 100644 --- a/pkg/observ/tracing.go +++ b/pkg/observ/tracing.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/gobuffalo/buffalo" - "github.com/gomods/athens/pkg/config/env" "github.com/gomods/athens/pkg/errors" "go.opencensus.io/exporter/jaeger" "go.opencensus.io/trace" @@ -20,15 +19,14 @@ type observabilityContext struct { // RegisterTraceExporter returns a jaeger exporter for exporting traces to opencensus. // It should in the future have a nice sampling rate defined // TODO: Extend beyond jaeger -func RegisterTraceExporter(service, ENV string) (*(jaeger.Exporter), error) { +func RegisterTraceExporter(URL, service, ENV string) (*(jaeger.Exporter), error) { const op errors.Op = "RegisterTracer" - collectorEndpointURI := env.TraceExporterURL() - if collectorEndpointURI == "" { + if URL == "" { return nil, errors.E(op, "Exporter URL is empty. Traces won't be exported") } je, err := jaeger.NewExporter(jaeger.Options{ - Endpoint: collectorEndpointURI, + Endpoint: URL, ServiceName: service, })