fix(config): Fix extrafields / attribute on logger / tracing
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Matthieu 'JP' DERASSE 2023-01-10 21:26:51 +00:00
parent 582a9e6192
commit 5a0beb9e2c
Signed by: mderasse
GPG Key ID: 55141C777B16A705
2 changed files with 10 additions and 2 deletions

View File

@ -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))
}

View File

@ -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))
}