-
Notifications
You must be signed in to change notification settings - Fork 195
Add telemetry for databricks aitools install
#5862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
parthban-db
wants to merge
1
commit into
main
Choose a base branch
from
parthban-db/stack/telemetry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+166
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package aitools | ||
|
|
||
| import ( | ||
| "context" | ||
| "slices" | ||
|
|
||
| "github.com/databricks/cli/cmd/root" | ||
| "github.com/databricks/cli/libs/telemetry" | ||
| "github.com/databricks/cli/libs/telemetry/protos" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // tryConfigureAuth resolves auth config onto the context so telemetry can | ||
| // upload at command exit. It does not fail if auth is not configured. | ||
| func tryConfigureAuth(cmd *cobra.Command, args []string) error { | ||
| ctx := root.SkipPrompt(cmd.Context()) | ||
| ctx = root.SkipLoadBundle(ctx) | ||
| cmd.SetContext(ctx) | ||
| _, _ = root.MustAnyClient(cmd, args) | ||
| return nil | ||
| } | ||
|
|
||
| // installOpts is the subset of install options telemetry records, kept narrow | ||
| // so every field that leaves the machine is visible here. | ||
| type installOpts struct { | ||
| Scope string | ||
| Experimental bool | ||
| } | ||
|
|
||
| // logInstallEvent buffers an install event; cmd/root uploads it at exit. | ||
| func logInstallEvent(ctx context.Context, plan []agentPlanItem, opts installOpts) { | ||
| telemetry.Log(ctx, protos.DatabricksCliLog{ | ||
| AitoolsInstallEvent: &protos.AitoolsInstallEvent{ | ||
| Agents: agentsField(plan), | ||
| Scope: opts.Scope, | ||
| Experimental: opts.Experimental, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| // agentsField returns the deduped agent names from the plan, sorted so the | ||
| // same set of agents always produces the same array on the analytics side. | ||
| func agentsField(plan []agentPlanItem) []string { | ||
| if len(plan) == 0 { | ||
| return nil | ||
| } | ||
| names := make([]string, 0, len(plan)) | ||
| seen := make(map[string]struct{}, len(plan)) | ||
| for _, it := range plan { | ||
| if it.agent == nil { | ||
| continue | ||
| } | ||
| name := it.agent.Name | ||
| if _, ok := seen[name]; ok { | ||
| continue | ||
| } | ||
| seen[name] = struct{}{} | ||
| names = append(names, name) | ||
| } | ||
| slices.Sort(names) | ||
| return names | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package aitools | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/libs/aitools/agents" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestAgentsField(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| plan []agentPlanItem | ||
| want []string | ||
| }{ | ||
| { | ||
| name: "empty plan", | ||
| plan: nil, | ||
| want: nil, | ||
| }, | ||
| { | ||
| name: "single agent", | ||
| plan: []agentPlanItem{{agent: &agents.Agent{Name: agents.NameClaudeCode}}}, | ||
| want: []string{"claude-code"}, | ||
| }, | ||
| { | ||
| name: "multiple agents are sorted", | ||
| plan: []agentPlanItem{ | ||
| {agent: &agents.Agent{Name: agents.NameCursor}}, | ||
| {agent: &agents.Agent{Name: agents.NameClaudeCode}}, | ||
| {agent: &agents.Agent{Name: agents.NameCodex}}, | ||
| }, | ||
| want: []string{"claude-code", "codex", "cursor"}, | ||
| }, | ||
| { | ||
| name: "duplicates are deduplicated", | ||
| plan: []agentPlanItem{ | ||
| {agent: &agents.Agent{Name: agents.NameClaudeCode}}, | ||
| {agent: &agents.Agent{Name: agents.NameClaudeCode}}, | ||
| }, | ||
| want: []string{"claude-code"}, | ||
| }, | ||
| { | ||
| name: "nil agent entries are skipped", | ||
| plan: []agentPlanItem{ | ||
| {agent: nil}, | ||
| {agent: &agents.Agent{Name: agents.NameCursor}}, | ||
| }, | ||
| want: []string{"cursor"}, | ||
| }, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| got := agentsField(tc.plan) | ||
| assert.Equal(t, tc.want, got) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package protos | ||
|
|
||
| // AitoolsInstallEvent is emitted on every execution of the `databricks aitools | ||
| // install` command. Every field is drawn from a closed set defined in the | ||
| // CLI, so the event carries no free text and no user data. | ||
| type AitoolsInstallEvent struct { | ||
| // Agent names the user targeted, deduplicated and sorted so the array is | ||
| // stable across invocations. Values come from the CLI's closed agent | ||
| // registry: claude-code, cursor, codex, opencode, github-copilot, | ||
| // antigravity. | ||
| Agents []string `json:"agents,omitempty"` | ||
|
|
||
| // Install scope: "project" (installed under the current working directory) | ||
| // or "global" (installed for the whole user). | ||
| Scope string `json:"scope,omitempty"` | ||
|
|
||
| // Whether the user passed --experimental to include experimental skills. | ||
| Experimental bool `json:"experimental,omitempty"` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the logger for the telemetry because otherwise, it will panic. A logger is always present in the production path through the root command.