Skip to content

Gitpod CLI: Improve Segment logging #19064

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

Merged
merged 8 commits into from
Nov 17, 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
2 changes: 1 addition & 1 deletion components/ide-proxy/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ packages:
- "conf/**"
- "static/**"
deps:
- components/local-app:app
- components/local-app:app-with-manifest
argdeps:
- imageRepoBase
config:
Expand Down
2 changes: 1 addition & 1 deletion components/ide-proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FROM cgr.dev/chainguard/wolfi-base:latest@sha256:5fd82be4dfccc650c1985d57847f1af
RUN apk add brotli gzip

# Gitpod CLI and Local App
COPY components-local-app--app/bin/* /bin/
COPY components-local-app--app-with-manifest/bin/* /bin/

RUN for FILE in `ls /bin/gitpod-local-companion*`;do \
gzip -v -f -9 -k "$FILE"; \
Expand Down
2 changes: 1 addition & 1 deletion components/local-app/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var rootCmd = &cobra.Command{
if gpctx, err := cfg.GetActiveContext(); err == nil && gpctx != nil {
telemetryEnabled = telemetryEnabled && gpctx.Host.String() == "https://gitpod.io"
}
telemetry.Init(telemetryEnabled, cfg.Telemetry.Identity, constants.Version.String())
telemetry.Init(telemetryEnabled, cfg.Telemetry.Identity, constants.Version.String(), level)
telemetry.RecordCommand(cmd)

if !isVersionCommand(cmd) {
Expand Down
19 changes: 16 additions & 3 deletions components/local-app/pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"crypto/sha256"
"errors"
"fmt"
"io"
"log"
"log/slog"
"math/rand"
"net"
Expand All @@ -33,8 +35,8 @@ var opts struct {
client segment.Client
}

// Init initialises the telemetry
func Init(enabled bool, identity, version string) {
// Init initializes the telemetry
func Init(enabled bool, identity, version string, logLevel slog.Level) {
opts.Enabled = enabled
if !enabled {
return
Expand All @@ -44,7 +46,18 @@ func Init(enabled bool, identity, version string) {
opts.Identity = identity

if segmentKey != "" {
opts.client = segment.New(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,
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/proxy/conf/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ https://{$GITPOD_DOMAIN} {
}

@ide_bin {
path /static/bin/gitpod-*
path /static/bin/*
}
handle @ide_bin {
import compression
Expand Down