Add default config to service.

Also modify `GetServiceTraceProvider` to keep working if nil or nil
interface is passed.
This commit is contained in:
Daniël Franke
2023-07-27 11:25:32 +02:00
parent c76b2e75ef
commit 22f5a76829
2 changed files with 19 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/url"
"reflect"
"strings"
"time"
@@ -29,7 +30,13 @@ var Propagator = propagation.NewCompositeTextMapPropagator(
// GetServiceTraceProvider returns a configured open-telemetry trace provider.
func GetServiceTraceProvider(c ConfigConverter, serviceName string) (trace.TracerProvider, error) {
cfg := c.Convert()
var cfg Config
if c == nil || reflect.ValueOf(c).IsNil() {
cfg = Config{Enabled: false}
} else {
cfg = c.Convert()
}
if cfg.Enabled {
return GetTraceProvider(cfg.Endpoint, cfg.Collector, serviceName, cfg.Type)
}

View File

@@ -59,6 +59,17 @@ func EnsureDefaults(cfg *config.Config) {
cfg.Log = &config.Log{}
}
if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil {
cfg.Tracing = &config.Tracing{
Enabled: cfg.Commons.Tracing.Enabled,
Type: cfg.Commons.Tracing.Type,
Endpoint: cfg.Commons.Tracing.Endpoint,
Collector: cfg.Commons.Tracing.Collector,
}
} else if cfg.Tracing == nil {
cfg.Tracing = &config.Tracing{}
}
if cfg.GRPCClientTLS == nil && cfg.Commons != nil {
cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS)
}