From 5a0beb9e2c16cd1b59bec1818b40a907c5477c16 Mon Sep 17 00:00:00 2001 From: Matthieu 'JP' DERASSE Date: Tue, 10 Jan 2023 21:26:51 +0000 Subject: [PATCH] fix(config): Fix extrafields / attribute on logger / tracing --- log/config.go | 6 +++++- tracing/config.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/log/config.go b/log/config.go index 1759f21..253eb1e 100644 --- a/log/config.go +++ b/log/config.go @@ -114,9 +114,13 @@ func (c *ConfigStruct) applyEnv() error { // Extra Fields if v := os.Getenv(fmt.Sprintf("%s%s", envPrefix, "EXTRA_FIELDS")); v != "" { + if c.ExtrasFields == nil { + c.ExtrasFields = make(map[string]interface{}) + } + extraFieldsPart := strings.Split(v, ",") for _, efp := range extraFieldsPart { - extraFieldKV := strings.SplitN(efp, ":", 1) + extraFieldKV := strings.SplitN(efp, ":", 2) if len(extraFieldKV) != 2 { return errors.NotValidf(fmt.Sprintf("Invalid extra_field %s in environment variable. Should be a key1:value1,key2:value2 format", efp)) } diff --git a/tracing/config.go b/tracing/config.go index 19de364..03df409 100644 --- a/tracing/config.go +++ b/tracing/config.go @@ -116,9 +116,13 @@ func (c *ConfigStruct) applyEnv() error { // Attributes if v := os.Getenv(fmt.Sprintf("%s%s", envPrefix, "ATTRIBUTES")); v != "" { + if c.Attributes == nil { + c.Attributes = make(map[string]string) + } + attributeParts := strings.Split(v, ",") for _, ap := range attributeParts { - attributeKV := strings.SplitN(ap, ":", 1) + attributeKV := strings.SplitN(ap, ":", 2) if len(attributeKV) != 2 { return errors.NotValidf(fmt.Sprintf("Invalid attribute %s in environment variable. Should be a key1:value1,key2:value2 format", ap)) }