Skip to content

Commit

Permalink
cli: use the gitpod endpoint for analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek committed Nov 21, 2023
1 parent 6f7ff4f commit 5b5cf95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions components/local-app/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,16 @@ 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 {
telemetryEnabled = telemetryEnabled && gpctx.Host.String() == host
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
7 changes: 4 additions & 3 deletions components/local-app/pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

// Injected at build time
var segmentKey = "TgiJIVvFsBGwmxbnnt5NeeDaian9nr3n"
var segmentKey = "untrusted-dummy-key"

var opts struct {
Enabled bool
Expand All @@ -36,7 +36,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 @@ -56,7 +56,8 @@ func Init(enabled bool, identity, version string, logLevel slog.Level) {
logger = segment.StdLogger(log)
}
opts.client, _ = segment.NewWithConfig(segmentKey, segment.Config{
Logger: logger,
Logger: logger,
Endpoint: host + "/analytics",
})
}
}
Expand Down

0 comments on commit 5b5cf95

Please sign in to comment.