Skip to content

Commit 19a1183

Browse files
authored
Track panics in sentry (#372)
## Summary I noticed that a lot of the shell-related functionality have `panics` and we have no idea if they are happening or not until some reports come in. This is to inform us on the panics and proactively fix issues ## How was it tested? devbox run build ./devbox shell on invalid base shell
1 parent a644ee5 commit 19a1183

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ require (
3636
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
3737
github.com/davecgh/go-spew v1.1.1 // indirect
3838
github.com/dsnet/compress v0.0.1 // indirect
39-
github.com/getsentry/sentry-go v0.15.0 // indirect
39+
github.com/getsentry/sentry-go v0.16.0 // indirect
4040
github.com/golang/snappy v0.0.4 // indirect
4141
github.com/google/uuid v1.3.0 // indirect
4242
github.com/inconshreveable/mousetrap v1.0.1 // indirect
@@ -55,7 +55,7 @@ require (
5555
github.com/therootcompany/xz v1.0.1 // indirect
5656
github.com/ulikunitz/xz v0.5.10 // indirect
5757
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
58-
golang.org/x/sys v0.2.0 // indirect
58+
golang.org/x/sys v0.3.0 // indirect
5959
golang.org/x/term v0.2.0 // indirect
60-
golang.org/x/text v0.4.0 // indirect
60+
golang.org/x/text v0.5.0 // indirect
6161
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
3838
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
3939
github.com/getsentry/sentry-go v0.15.0 h1:CP9bmA7pralrVUedYZsmIHWpq/pBtXTSew7xvVpfLaA=
4040
github.com/getsentry/sentry-go v0.15.0/go.mod h1:RZPJKSw+adu8PBNygiri/A98FqVr2HtRckJk9XVxJ9I=
41+
github.com/getsentry/sentry-go v0.16.0 h1:owk+S+5XcgJLlGR/3+3s6N4d+uKwqYvh/eS0AIMjPWo=
42+
github.com/getsentry/sentry-go v0.16.0/go.mod h1:ZXCloQLj0pG7mja5NK6NPf2V4A88YJ4pNlc2mOHwh6Y=
4143
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
4244
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
4345
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
@@ -134,12 +136,16 @@ golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBc
134136
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
135137
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
136138
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
139+
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
140+
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
137141
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
138142
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
139143
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
140144
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
141145
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
142146
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
147+
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
148+
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
143149
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
144150
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
145151
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=

internal/boxcli/midcobra/telemetry.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/denisbrodbeck/machineid"
15+
"github.com/getsentry/sentry-go"
1516
segment "github.com/segmentio/analytics-go"
1617
"github.com/spf13/cobra"
1718
"go.jetpack.io/devbox"
@@ -55,15 +56,17 @@ var _ Middleware = (*telemetryMiddleware)(nil)
5556

5657
func (m *telemetryMiddleware) preRun(cmd *cobra.Command, args []string) {
5758
m.startTime = time.Now()
59+
if !m.disabled {
60+
sentry := telemetry.NewSentry(m.opts.SentryDSN)
61+
sentry.Init(m.opts.AppName, m.opts.AppVersion, m.executionID)
62+
}
5863
}
5964

6065
func (m *telemetryMiddleware) postRun(cmd *cobra.Command, args []string, runErr error) {
6166
if m.disabled {
6267
return
6368
}
6469

65-
sentry := telemetry.NewSentry(m.opts.SentryDSN)
66-
sentry.Init(m.opts.AppName, m.opts.AppVersion, m.executionID)
6770
segmentClient, _ := segment.NewWithConfig(m.opts.TelemetryKey, segment.Config{
6871
BatchSize: 1, /* no batching */
6972
// Discard logs:

internal/cloud/openssh/sshshim/command.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import (
1313

1414
func Execute(ctx context.Context, args []string) int {
1515
defer debug.Recover()
16+
sentry := initSentry()
1617

1718
err := execute(args)
1819

19-
logSentry(err)
20+
sentry.CaptureException(err)
2021

2122
if err != nil {
2223
return 1
@@ -44,9 +45,10 @@ func execute(args []string) error {
4445
return nil
4546
}
4647

47-
func logSentry(runErr error) {
48+
func initSentry() *telemetry.Sentry {
4849
const appName = "devbox-sshshim"
4950
s := telemetry.NewSentry(build.SentryDSN)
5051
s.Init(appName, build.Version, midcobra.ExecutionID())
51-
s.CaptureException(runErr)
52+
53+
return s
5254
}

internal/debug/debug.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"strconv"
99

10+
"github.com/getsentry/sentry-go"
1011
"github.com/pkg/errors"
1112
)
1213

@@ -42,6 +43,7 @@ func Recover() {
4243
return
4344
}
4445

46+
sentry.CurrentHub().Recover(r)
4547
if enabled {
4648
log.Println("Allowing panic because debug mode is enabled.")
4749
panic(r)

internal/telemetry/sentry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func (s *Sentry) Init(appName, appVersion, executionID string) {
3333
}
3434

3535
_ = sentry.Init(sentry.ClientOptions{
36+
AttachStacktrace: true,
3637
Dsn: s.dsn,
3738
Environment: environment,
3839
Release: release,

0 commit comments

Comments
 (0)