Skip to content

Commit b346d9c

Browse files
authored
feat: add organization name to metrics (#2439)
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
1 parent 1176e3e commit b346d9c

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

app/cli/cmd/root.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,13 @@ func recordCommand(executedCmd *cobra.Command, authInfo *token.ParsedToken) erro
410410
}
411411

412412
cmdTracker := telemetry.NewCommandTracker(telemetryClient)
413+
controlplaneURL, controlplaneHash := hashControlPlaneURL()
414+
413415
tags := telemetry.Tags{
414-
"cli_version": Version,
415-
"cp_url_hash": hashControlPlaneURL(),
416-
"chainloop_source": "cli",
416+
"cli_version": Version,
417+
"cp_url_hash": controlplaneHash,
418+
"cp_installation_url": controlplaneURL,
419+
"chainloop_source": "cli",
417420
}
418421

419422
// It tries to extract the token from the context and add it to the tags. If it fails, it will ignore it.
@@ -423,6 +426,12 @@ func recordCommand(executedCmd *cobra.Command, authInfo *token.ParsedToken) erro
423426
tags["org_id"] = authInfo.OrgID
424427
}
425428

429+
// Add organization name if available
430+
orgName := viper.GetString(confOptions.organization.viperKey)
431+
if orgName != "" {
432+
tags["organization_name"] = orgName
433+
}
434+
426435
if err = cmdTracker.Track(executedCmd.Context(), extractCmdLineFromCommand(executedCmd), tags); err != nil {
427436
return fmt.Errorf("sending event: %w", err)
428437
}
@@ -446,10 +455,9 @@ func extractCmdLineFromCommand(cmd *cobra.Command) string {
446455
}
447456

448457
// hashControlPlaneURL returns a hash of the control plane URL
449-
func hashControlPlaneURL() string {
450-
url := viper.GetString("control-plane.API")
451-
452-
return fmt.Sprintf("%x", sha256.Sum256([]byte(url)))
458+
func hashControlPlaneURL() (url string, hash string) {
459+
url = viper.GetString(confOptions.controlplaneAPI.viperKey)
460+
return url, fmt.Sprintf("%x", sha256.Sum256([]byte(url)))
453461
}
454462

455463
func apiInsecure() bool {

0 commit comments

Comments
 (0)