-
Notifications
You must be signed in to change notification settings - Fork 237
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
Add telemetry to the CLI #958
Conversation
3c3619e
to
82bce56
Compare
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.
A lot of open discussions, mostly naming, structure, and semantics. No major conceptual objections. Let's discuss.
15f00bd
to
7dc76da
Compare
4be1329
to
9bc7df0
Compare
This seems problematic in an air-gapped server environment. What is the UX like there? EDIT: Took this to Slack https://circleci.slack.com/archives/C034BLFP326/p1689092028572929 |
455a8a7
to
c02a2e5
Compare
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.
Great work here! Massive addition to our CLI product telemetry. The way the client is built and tested seems sound to me.
The only part I'm uncomfortable with is the client lifecycle patterns. Creating a new client in the PreRun
, PersistentPreRun
or Run
depending on the case.
I have a feeling this could be done in a simpler fashion. As far as I understand, we want a single telemetry client per run, we want it throughout the command execution, we want to batch all the events, and then, when the execution is done, we want to send all of our events to analytics.
If this is the case, it sounds like our telemetry client would live well in the Command
's Context
. What do you think of doing something like:
cmd/root.go
const telemetryClientCtxKey = "telemetry_client"
func Execute() {
header.SetCommandStr(CommandStr())
command := MakeCommands()
telemetry := CreateTelemetry(rootOptions)
defer telemetry.Close()
command.setContext(
context.WithValue(
command.Context(),
telemetryClientCtxKey,
telemetry,
),
)
err := command.Execute()
if err != nil {
os.Exit(-1)
}
}
cmd/config.go
packCommand := &cobra.Command{
Use: "pack <path>",
Short: "Pack up your CircleCI configuration into a single file.",
RunE: func(cmd *cobra.Command, args []string) error {
err := packConfig(args)
telemetryClient, ok := cmd.Context().Value(create_telemetry.ContextKey{}).(telemetry.Client)
if ok {
telemetryClient.Track(telemetry.CreateConfigEvent(create_telemetry.GetCommandInformation(cmd, true), err))
}
return err
},
Using a string constant as a context key is not Good Go™, but it seems acceptable in our CLI context. Available to discuss alternatives.
Does this proposal make sense to you?
About your proposition, I completely understand it and I first thought about doing something like this but I decided to go the long way by implementing the creation / closing of telemetry for every command because of product reason. First reason is pretty minor but I like the fact that you are asked telemetry only on commands that send telemetry events. For example is you only use the CLI to set your projects' secrets you may never know about this telemetry. That being said those are kinda minor points and we may consider that having a more standard way to use the telemetry in the code is more important than the reasons I mention. Open to discuss this in a call if you want EDIT: As I was reading your comments I came up with a way to implement this in a good generic way in this comment |
Also changed the way we check for telemetry events in E2E tests
Moved the key inside the code because it was not possible not to add it to the Homebrew formula so we decided to write it in the code directly
3a8248c
to
184aca4
Compare
184aca4
to
1e32523
Compare
Checklist
Internal Checklist
Changes
Ticket: https://circleci.atlassian.net/browse/DEVEX-889
Rationale
Product was having trouble seeing how the CLI was used and asked us to add telemetry
Considerations
Know there is a PR on homebrew core to change the build in order to enable telemetry for homebrew users
Screenshots
On your first time using the CLI it will ask you for your approval like this: