Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions app/cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,13 @@ func recordCommand(executedCmd *cobra.Command, authInfo *token.ParsedToken) erro
}

cmdTracker := telemetry.NewCommandTracker(telemetryClient)
controlplaneURL, controlplaneHash := hashControlPlaneURL()

tags := telemetry.Tags{
"cli_version": Version,
"cp_url_hash": hashControlPlaneURL(),
"chainloop_source": "cli",
"cli_version": Version,
"cp_url_hash": controlplaneHash,
"cp_installation_url": controlplaneURL,
"chainloop_source": "cli",
}

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

// Add organization name if available
orgName := viper.GetString(confOptions.organization.viperKey)
if orgName != "" {
tags["organization_name"] = orgName
}

if err = cmdTracker.Track(executedCmd.Context(), extractCmdLineFromCommand(executedCmd), tags); err != nil {
return fmt.Errorf("sending event: %w", err)
}
Expand All @@ -447,10 +456,9 @@ func extractCmdLineFromCommand(cmd *cobra.Command) string {
}

// hashControlPlaneURL returns a hash of the control plane URL
func hashControlPlaneURL() string {
url := viper.GetString("control-plane.API")

return fmt.Sprintf("%x", sha256.Sum256([]byte(url)))
func hashControlPlaneURL() (url string, hash string) {
url = viper.GetString(confOptions.controlplaneAPI.viperKey)
return url, fmt.Sprintf("%x", sha256.Sum256([]byte(url)))
}

func apiInsecure() bool {
Expand Down
Loading