Skip to content

Commit e1c1281

Browse files
authored
[telemetry] update event name and change is_cloud to shell_access kind (#562)
## Summary Updating: 1. Event name to be of the form: `[devbox] Shell event: interactive` which is consistent with the command event names. 2. Changing is_cloud to shell_access with values `local | ssh | browser` ## How was it tested? - [x] Need to test 1. apply development keys for segment and sentry 2. `local`: run local `devbox shell` and verify event logged in segment dashboard. 3. `ssh`: deploy custom VM with custom devbox binary. verify event logged in segment dashboard. 4. `browser`: Follow devbox-cloud README for http-gateway, but how do I test the custom devbox binary?
1 parent 2fe719c commit e1c1281

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

devbox-linux-amd64

21.7 MB
Binary file not shown.

internal/nix/shell.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,9 @@ var envToKeep = map[string]bool{
588588
"SHELL_SESSIONS_DISABLE": true, // Respect session save/resume setting (see /etc/zshrc_Apple_Terminal).
589589
"SECURITYSESSIONID": true,
590590

591+
// SSH variables
592+
"SSH_TTY": true, // Used by devbox telemetry logging
593+
591594
// Nix + Devbox
592595
//
593596
// Variables specific to running in a Nix shell and devbox shell.

internal/telemetry/segment.go

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"crypto/hmac"
55
"crypto/sha256"
66
"encoding/hex"
7+
"fmt"
78
"io"
89
"log"
910
"os"
1011
"strconv"
12+
"strings"
1113
"time"
1214

1315
"github.com/pkg/errors"
14-
"github.com/samber/lo"
1516
segment "github.com/segmentio/analytics-go"
1617
"go.jetpack.io/devbox/internal/build"
1718
"go.jetpack.io/devbox/internal/cloud/openssh"
@@ -31,12 +32,13 @@ type Event struct {
3132
UserID string
3233
}
3334

34-
// ttiEvent contains fields used to log the time-to-interactive event. For now,
35-
// this is used for devbox shell (local and cloud).
36-
type ttiEvent struct {
37-
Event
38-
eventName string
39-
}
35+
type shellAccessKind string
36+
37+
const (
38+
local shellAccessKind = "local"
39+
ssh shellAccessKind = "ssh"
40+
browser shellAccessKind = "browser"
41+
)
4042

4143
// NewSegmentClient returns a client object to use for segment logging.
4244
// Callers are responsible for calling client.Close().
@@ -75,17 +77,14 @@ func LogShellDurationEvent(eventName string, startTime string) error {
7577
return errors.WithStack(err)
7678
}
7779

78-
evt := ttiEvent{
79-
Event: Event{
80-
AnonymousID: DeviceID(),
81-
AppName: opts.AppName,
82-
AppVersion: opts.AppVersion,
83-
CloudRegion: os.Getenv("DEVBOX_REGION"),
84-
Duration: time.Since(start),
85-
OsName: OS(),
86-
UserID: UserIDFromGithubUsername(),
87-
},
88-
eventName: eventName,
80+
evt := Event{
81+
AnonymousID: DeviceID(),
82+
AppName: opts.AppName,
83+
AppVersion: opts.AppVersion,
84+
CloudRegion: os.Getenv("DEVBOX_REGION"),
85+
Duration: time.Since(start),
86+
OsName: OS(),
87+
UserID: UserIDFromGithubUsername(),
8988
}
9089

9190
segmentClient := NewSegmentClient(build.TelemetryKey)
@@ -96,7 +95,8 @@ func LogShellDurationEvent(eventName string, startTime string) error {
9695
// Ignore errors, telemetry is best effort
9796
_ = segmentClient.Enqueue(segment.Track{
9897
AnonymousId: evt.AnonymousID,
99-
Event: evt.eventName,
98+
// Event name. We trim the prefix from shell-interactive/shell-ready to avoid redundancy.
99+
Event: fmt.Sprintf("[%s] Shell Event: %s", evt.AppName, strings.TrimPrefix(eventName, "shell-")),
100100
Context: &segment.Context{
101101
Device: segment.DeviceInfo{
102102
Id: evt.AnonymousID,
@@ -110,7 +110,7 @@ func LogShellDurationEvent(eventName string, startTime string) error {
110110
},
111111
},
112112
Properties: segment.NewProperties().
113-
Set("is_cloud", lo.Ternary(evt.CloudRegion != "", "true", "false")).
113+
Set("shell_access", shellAccess()).
114114
Set("duration", evt.Duration.Milliseconds()),
115115
UserId: evt.UserID,
116116
})
@@ -154,3 +154,15 @@ func timeFromUnixTimestamp(timestamp string) (time.Time, error) {
154154
func UnixTimestampFromTime(t time.Time) string {
155155
return strconv.FormatInt(t.Unix(), 10)
156156
}
157+
158+
func shellAccess() shellAccessKind {
159+
// Check if running in devbox cloud
160+
if os.Getenv("DEVBOX_REGION") != "" {
161+
// Check if running via ssh tty (i.e. ssh shell)
162+
if os.Getenv("SSH_TTY") != "" {
163+
return ssh
164+
}
165+
return browser
166+
}
167+
return local
168+
}

0 commit comments

Comments
 (0)