Skip to content

Commit 9ab3fd2

Browse files
authored
Add tags to project metrics (#2623)
* Add tags to project metrics This adds a few tags that I've found useful for our monitoring of a many-project terraform repository. There are likely more tags that can be added in other areas, but I figured I'd start small and get feedback before increasing the blast radius * Add labels, handle nils, alphabetize * Move //nolint to line of assignment
1 parent 117ce59 commit 9ab3fd2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

server/events/command/project_context.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package command
22

33
import (
44
"fmt"
5+
"strconv"
56
"strings"
67

78
"github.com/hashicorp/go-version"
@@ -96,7 +97,18 @@ type ProjectContext struct {
9697
// SetScope sets the scope of the stats object field. Note: we deliberately set this on the value
9798
// instead of a pointer since we want scopes to mirror our function stack
9899
func (p ProjectContext) SetScope(scope string) {
99-
p.Scope = p.Scope.SubScope(scope) //nolint
100+
v := ""
101+
if p.TerraformVersion != nil {
102+
v = p.TerraformVersion.String()
103+
}
104+
p.Scope = p.Scope.SubScope(scope).Tagged(map[string]string{ //nolint
105+
"base_repo": p.BaseRepo.FullName,
106+
"pr_number": strconv.Itoa(p.Pull.Num),
107+
"project": p.ProjectName,
108+
"project_path": p.RepoRelDir,
109+
"terraform_version": v,
110+
"workspace": p.Workspace,
111+
})
100112
}
101113

102114
// GetShowResultFileName returns the filename (not the path) to store the tf show result

0 commit comments

Comments
 (0)