Skip to content
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

Merged
merged 29 commits into from
Aug 2, 2023
Merged

Conversation

JulesFaucherre
Copy link
Contributor

@JulesFaucherre JulesFaucherre commented Jun 27, 2023

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have checked for similar issues and haven't found anything relevant.
  • This is not a security issue (which should be reported here: https://circleci.com/security/)
  • I have read Contribution Guidelines.

Internal Checklist

  • I am requesting a review from my own team as well as the owning team
  • I have a plan in place for the monitoring of the changes that I am making (this can include new monitors, logs to be aware of, etc...)

Changes

Ticket: https://circleci.atlassian.net/browse/DEVEX-889

  • Added a telemetry client in the CLI
  • Telemetry events added on different parts of the code. The implementation of such tests are best effort so some commands are not tested for telemetry

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:
Capture d’écran 2023-07-24 à 09 41 54

@JulesFaucherre JulesFaucherre force-pushed the task/DEVEX-898/cli-telemetry branch from 3c3619e to 82bce56 Compare June 27, 2023 16:33
Copy link
Contributor

@loderunner loderunner left a 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.

cmd/check_telemetry.go Outdated Show resolved Hide resolved
cmd/check_telemetry.go Outdated Show resolved Hide resolved
settings/settings.go Outdated Show resolved Hide resolved
cmd/check_telemetry.go Outdated Show resolved Hide resolved
cmd/check_telemetry.go Outdated Show resolved Hide resolved
cmd/check_telemetry.go Outdated Show resolved Hide resolved
settings/settings.go Show resolved Hide resolved
settings/settings.go Show resolved Hide resolved
settings/settings.go Outdated Show resolved Hide resolved
cmd/check_telemetry_test.go Outdated Show resolved Hide resolved
@JulesFaucherre JulesFaucherre force-pushed the task/DEVEX-898/cli-telemetry branch 12 times, most recently from 15f00bd to 7dc76da Compare July 11, 2023 14:09
@JulesFaucherre JulesFaucherre marked this pull request as ready for review July 11, 2023 15:42
@JulesFaucherre JulesFaucherre requested review from a team as code owners July 11, 2023 15:42
@JulesFaucherre JulesFaucherre force-pushed the task/DEVEX-898/cli-telemetry branch 2 times, most recently from 4be1329 to 9bc7df0 Compare July 11, 2023 15:47
@ryanwohara
Copy link
Contributor

ryanwohara commented Jul 11, 2023

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

@JulesFaucherre JulesFaucherre force-pushed the task/DEVEX-898/cli-telemetry branch 7 times, most recently from 455a8a7 to c02a2e5 Compare July 13, 2023 13:36
Copy link
Contributor

@loderunner loderunner left a 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?

Taskfile.yml Outdated Show resolved Hide resolved
cmd/build.go Outdated Show resolved Hide resolved
cmd/config.go Outdated Show resolved Hide resolved
telemetry/telemetry.go Outdated Show resolved Hide resolved
settings/settings.go Outdated Show resolved Hide resolved
@JulesFaucherre
Copy link
Contributor Author

JulesFaucherre commented Jul 13, 2023

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.
Second reason is a edge case: for the circleci setup it is more logical in terms of code and more coherent in terms of UX to get asked about telemetry after you have answer all the setup input. In a code point of view because, at that point you have the user id and the host so you can save the user's information before sending the telemetry event. In a UX point of view because it feels more natural to be asked about telemetry as the last step of setting up your CLI

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

@JulesFaucherre JulesFaucherre force-pushed the task/DEVEX-898/cli-telemetry branch from 3a8248c to 184aca4 Compare August 1, 2023 14:07
@JulesFaucherre JulesFaucherre force-pushed the task/DEVEX-898/cli-telemetry branch from 184aca4 to 1e32523 Compare August 1, 2023 14:24
@JulesFaucherre JulesFaucherre merged commit 1d65ffc into develop Aug 2, 2023
@JulesFaucherre JulesFaucherre deleted the task/DEVEX-898/cli-telemetry branch August 2, 2023 08:06
@JulesFaucherre JulesFaucherre mentioned this pull request Aug 9, 2023
5 tasks
@JulesFaucherre JulesFaucherre mentioned this pull request Sep 6, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants