Skip to content

Commit

Permalink
cli: use the gitpod endpoint for analytics (#19109)
Browse files Browse the repository at this point in the history
* cli: use the gitpod endpoint for analytics

* Remove gitpod.io constraint

* Remove unused tomfoolery

* bump version
  • Loading branch information
filiptronicek authored Nov 24, 2023
1 parent b6fa451 commit 96a480c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
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

0 comments on commit 96a480c

Please sign in to comment.