Skip to content

[telemetry] add nix.version to sentry and segment #1469

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 1 commit into from
Sep 12, 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 internal/boxcli/midcobra/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"go.jetpack.io/devbox"
"go.jetpack.io/devbox/internal/boxcli/featureflag"
"go.jetpack.io/devbox/internal/envir"
Expand Down Expand Up @@ -54,6 +53,7 @@ func (m *telemetryMiddleware) postRun(cmd *cobra.Command, args []string, runErr
}
meta.Command = subcmd.CommandPath()
meta.CommandFlags = flags

meta.Packages, meta.NixpkgsHash = getPackagesAndCommitHash(cmd)
meta.InShell = envir.IsDevboxShellEnabled()
meta.InBrowser = envir.IsInBrowser()
Expand Down
10 changes: 8 additions & 2 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ var (
Commit = "none"
CommitDate = "unknown"

SentryDSN = "" // Disabled by default
TelemetryKey = "" // Disabled by default
// SentryDSN is injected in the build from
// https://jetpack-io.sentry.io/settings/projects/devbox/keys/
// It is disabled by default.
SentryDSN = ""
// TelemetryKey is the Segment Write Key
// https://segment.com/docs/connections/sources/catalog/libraries/server/go/quickstart/
// It is disabled by default.
TelemetryKey = ""
)

// User-presentable names of operating systems supported by Devbox.
Expand Down
7 changes: 7 additions & 0 deletions internal/telemetry/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

segment "github.com/segmentio/analytics-go"
"go.jetpack.io/devbox/internal/nix"

"go.jetpack.io/devbox/internal/build"
"go.jetpack.io/devbox/internal/envir"
Expand All @@ -32,6 +33,11 @@ func initSegmentClient() bool {
}

func newTrackMessage(name string, meta Metadata) *segment.Track {
nixVersion, err := nix.Version()
if err != nil {
nixVersion = "unknown"
}

dur := time.Since(procStartTime)
if !meta.CommandStart.IsZero() {
dur = time.Since(meta.CommandStart)
Expand Down Expand Up @@ -63,6 +69,7 @@ func newTrackMessage(name string, meta Metadata) *segment.Track {
"packages": meta.Packages,
"shell": os.Getenv(envir.Shell),
"shell_access": shellAccess(),
"nix_version": nixVersion,
},
}
}
Expand Down
9 changes: 9 additions & 0 deletions internal/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/google/uuid"
"github.com/pkg/errors"
segment "github.com/segmentio/analytics-go"
"go.jetpack.io/devbox/internal/nix"

"go.jetpack.io/devbox/internal/build"
"go.jetpack.io/devbox/internal/envir"
Expand Down Expand Up @@ -117,6 +118,11 @@ func Error(err error, meta Metadata) {
return
}

nixVersion, err := nix.Version()
if err != nil {
nixVersion = "unknown"
}

event := &sentry.Event{
EventID: sentry.EventID(ExecutionID),
Level: sentry.LevelError,
Expand All @@ -133,6 +139,9 @@ func Error(err error, meta Metadata) {
"name": "Go",
"version": strings.TrimPrefix(runtime.Version(), "go"),
},
"nix": {
"version": nixVersion,
},
},
}
if meta.Command != "" {
Expand Down