feat: inprogress
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
@@ -34,9 +35,34 @@ func Init(ctx context.Context, name string) (context.Context, func() error) {
|
||||
}
|
||||
|
||||
func env(name, defaultValue string) string {
|
||||
if v := os.Getenv(name); v != "" {
|
||||
log.Println("# ", name, " = ", v)
|
||||
name = strings.TrimSpace(name)
|
||||
defaultValue = strings.TrimSpace(defaultValue)
|
||||
if v := strings.TrimSpace(os.Getenv(name)); v != "" {
|
||||
log.Println("# ", name, "=", v)
|
||||
return v
|
||||
}
|
||||
log.Println("# ", name, "=", defaultValue, "(default)")
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
type secret string
|
||||
|
||||
func (s secret) String() string {
|
||||
if s == "" {
|
||||
return "(nil)"
|
||||
}
|
||||
return "***"
|
||||
}
|
||||
func (s secret) Secret() string {
|
||||
return string(s)
|
||||
}
|
||||
func envSecret(name, defaultValue string) secret {
|
||||
name = strings.TrimSpace(name)
|
||||
defaultValue = strings.TrimSpace(defaultValue)
|
||||
if v := strings.TrimSpace(os.Getenv(name)); v != "" {
|
||||
log.Println("# ", name, "=", secret(v))
|
||||
return secret(v)
|
||||
}
|
||||
log.Println("# ", name, "=", secret(defaultValue), "(default)")
|
||||
return secret(defaultValue)
|
||||
}
|
||||
|
||||
@@ -64,13 +64,13 @@ func initLogger(name string) func() error {
|
||||
log.SetPrefix("[" + name + "] ")
|
||||
log.SetFlags(log.LstdFlags&^(log.Ldate|log.Ltime) | log.Lshortfile)
|
||||
|
||||
token := env("LOGZIO_LOG_TOKEN", "")
|
||||
token := envSecret("LOGZIO_LOG_TOKEN", "")
|
||||
if token == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
l, err := logzio.New(
|
||||
token,
|
||||
token.Secret(),
|
||||
// logzio.SetDebug(os.Stderr),
|
||||
logzio.SetUrl(env("LOGZIO_LOG_URL", "https://listener.logz.io:8071")),
|
||||
logzio.SetDrainDuration(time.Second*5),
|
||||
|
||||
@@ -71,9 +71,13 @@ func initTracing(ctx context.Context, name string) (context.Context, func() erro
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
exporterAddr := env("EV_TRACE_ENDPOINT", "")
|
||||
if exporterAddr == "" {
|
||||
return ctx, nil
|
||||
}
|
||||
traceExporter, err := otlptracehttp.New(ctx,
|
||||
otlptracehttp.WithInsecure(),
|
||||
otlptracehttp.WithEndpoint("localhost:4318"),
|
||||
otlptracehttp.WithEndpoint(exporterAddr),
|
||||
)
|
||||
if err != nil {
|
||||
log.Println(wrap(err, "failed to create trace exporter"))
|
||||
|
||||
Reference in New Issue
Block a user