From f5f11728e9d8f85eacc175016c10eac6c922f587 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Fri, 19 Sep 2025 11:02:53 +0200 Subject: [PATCH 1/2] feat(telemetry): improvements on org info Signed-off-by: Miguel Martinez --- app/cli/cmd/root.go | 22 +++++++++++++------ app/cli/internal/telemetry/posthog/posthog.go | 16 ++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/cli/cmd/root.go b/app/cli/cmd/root.go index 05a10d0c5..f294a75cc 100644 --- a/app/cli/cmd/root.go +++ b/app/cli/cmd/root.go @@ -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. @@ -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) } @@ -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 { diff --git a/app/cli/internal/telemetry/posthog/posthog.go b/app/cli/internal/telemetry/posthog/posthog.go index ee5e6648c..833aaa221 100644 --- a/app/cli/internal/telemetry/posthog/posthog.go +++ b/app/cli/internal/telemetry/posthog/posthog.go @@ -73,18 +73,16 @@ func (p *Tracker) TrackEvent(_ context.Context, eventName string, id string, tag msg.Properties.Set(k, v) } - // Assign the installation ID if available as a group. - // It creates a new group named cp_installation where the values are the cp_url_hash. + // Assign groups for installation and organization tracking + groups := posthog.NewGroups() if tags["cp_url_hash"] != "" { - msg.Groups = posthog. - NewGroups(). - Set("cp_installation", tags["cp_url_hash"]) + groups.Set("cp_installation", tags["cp_url_hash"]) } - // It creates a new group named org_id where the values are the org_id. if tags["org_id"] != "" { - msg.Groups = posthog. - NewGroups(). - Set("organization", tags["org_id"]) + groups.Set("organization", tags["org_id"]) + } + if len(groups) > 0 { + msg.Groups = groups } // Assign an alias to the userID in the following cases: // - The machine ID is available and different from the userID. From 1b6dfb222b626a868006ae27607366dd533d8873 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Fri, 19 Sep 2025 11:05:07 +0200 Subject: [PATCH 2/2] feat(telemetry): improvements on org info Signed-off-by: Miguel Martinez --- app/cli/internal/telemetry/posthog/posthog.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/cli/internal/telemetry/posthog/posthog.go b/app/cli/internal/telemetry/posthog/posthog.go index 833aaa221..ee5e6648c 100644 --- a/app/cli/internal/telemetry/posthog/posthog.go +++ b/app/cli/internal/telemetry/posthog/posthog.go @@ -73,16 +73,18 @@ func (p *Tracker) TrackEvent(_ context.Context, eventName string, id string, tag msg.Properties.Set(k, v) } - // Assign groups for installation and organization tracking - groups := posthog.NewGroups() + // Assign the installation ID if available as a group. + // It creates a new group named cp_installation where the values are the cp_url_hash. if tags["cp_url_hash"] != "" { - groups.Set("cp_installation", tags["cp_url_hash"]) + msg.Groups = posthog. + NewGroups(). + Set("cp_installation", tags["cp_url_hash"]) } + // It creates a new group named org_id where the values are the org_id. if tags["org_id"] != "" { - groups.Set("organization", tags["org_id"]) - } - if len(groups) > 0 { - msg.Groups = groups + msg.Groups = posthog. + NewGroups(). + Set("organization", tags["org_id"]) } // Assign an alias to the userID in the following cases: // - The machine ID is available and different from the userID.