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

cli: use the gitpod endpoint for analytics #19109

Merged
merged 5 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions components/local-app/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ var rootCmd = &cobra.Command{
}
cmd.SetContext(config.ToContext(context.Background(), cfg))

host := "https://gitpod.io"
telemetryEnabled := !telemetry.DoNotTrack()
telemetryEnabled = telemetryEnabled && cfg.Telemetry.Enabled
// For now we only enable telemetry on gitpod.io
if gpctx, err := cfg.GetActiveContext(); err == nil && gpctx != nil {
telemetryEnabled = telemetryEnabled && gpctx.Host.String() == "https://gitpod.io"
gpctx, err := cfg.GetActiveContext()
if err == nil && gpctx != nil {
host = gpctx.Host.String()
}
telemetry.Init(telemetryEnabled, cfg.Telemetry.Identity, constants.Version.String(), level)
telemetry.Init(telemetryEnabled, cfg.Telemetry.Identity, constants.Version.String(), level, host)
telemetry.RecordCommand(cmd)

if !isVersionCommand(cmd) {
Expand Down
30 changes: 13 additions & 17 deletions components/local-app/pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import (
"golang.org/x/exp/slices"
)

// Injected at build time
var segmentKey = "TgiJIVvFsBGwmxbnnt5NeeDaian9nr3n"

var opts struct {
Enabled bool
Identity string
Expand All @@ -36,7 +33,7 @@ var opts struct {
}

// Init initializes the telemetry
func Init(enabled bool, identity, version string, logLevel slog.Level) {
func Init(enabled bool, identity, version string, logLevel slog.Level, host string) {
opts.Enabled = enabled
if !enabled {
return
Expand All @@ -45,20 +42,19 @@ func Init(enabled bool, identity, version string, logLevel slog.Level) {
opts.Version = version
opts.Identity = identity

if segmentKey != "" {
var logger segment.Logger
if logLevel == slog.LevelDebug {
logger = segment.StdLogger(log.New(os.Stderr, "telemetry ", log.LstdFlags))
} else {
// we don't want to log anything
log := log.New(os.Stderr, "telemetry ", log.LstdFlags)
log.SetOutput(io.Discard)
logger = segment.StdLogger(log)
}
opts.client, _ = segment.NewWithConfig(segmentKey, segment.Config{
Logger: logger,
})
var logger segment.Logger
if logLevel == slog.LevelDebug {
logger = segment.StdLogger(log.New(os.Stderr, "telemetry ", log.LstdFlags))
} else {
// we don't want to log anything
log := log.New(os.Stderr, "telemetry ", log.LstdFlags)
log.SetOutput(io.Discard)
logger = segment.StdLogger(log)
}
opts.client, _ = segment.NewWithConfig("untrusted-dummy-key", segment.Config{
Logger: logger,
Endpoint: host + "/analytics",
})
}

// DoNotTrack returns true if the user opted out of telemetry
Expand Down
2 changes: 1 addition & 1 deletion components/local-app/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.2
0.1.3
Loading