Skip to content

Commit

Permalink
chore(telemetry): support extra attributes
Browse files Browse the repository at this point in the history
The user can define extra attributes for telemetry with environment variables (WERF_TELEMETRY_EXTRA_ATTRIBUTE_<any>="<key>=<value>").

Signed-off-by: Alexey Igrychev <alexey.igrychev@flant.com>
  • Loading branch information
alexey-igrychev committed Aug 14, 2022
1 parent e6678fb commit 8486114
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/telemetry/telemetrywerfio.go
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"os"
"runtime"
"sort"
"strings"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -170,6 +172,31 @@ func (t *TelemetryWerfIO) getAttributes() map[string]interface{} {
}
}

// add extra attributes
{
env := os.Environ()
sort.Strings(env)
for _, keyValue := range env {
parts := strings.SplitN(keyValue, "=", 2)
if strings.HasPrefix(parts[0], "WERF_TELEMETRY_EXTRA_ATTRIBUTE_") {
valueParts := strings.SplitN(parts[1], "=", 2)

attrKey := valueParts[0]
attrVal := valueParts[1]

// ignore reserved name
{
_, ok := attributes[attrKey]
if ok {
continue
}
}

attributes[attrKey] = attrVal
}
}
}

return attributes
}

Expand Down

0 comments on commit 8486114

Please sign in to comment.