mirror of
https://github.com/gomods/athens
synced 2026-02-03 12:10:32 +00:00
Use config for trace url (#681)
* Use config for trace url * pr updates * fix typo * fix typo
This commit is contained in:
@@ -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 {
|
||||
|
||||
+5
-1
@@ -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
|
||||
|
||||
Vendored
-8
@@ -1,8 +0,0 @@
|
||||
package env
|
||||
|
||||
import "os"
|
||||
|
||||
// TraceExporterURL returns where the trace is stored to
|
||||
func TraceExporterURL() string {
|
||||
return os.Getenv("TRACE_EXPORTER")
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user