Skip to content

Commit 161017a

Browse files
chore: Add Sentry DSN so crash reporting works in all builds (#1564)
* Hardcode Sentry DSN so crash reporting works in all builds The Sentry DSN was injected at build time via ldflags from a SENTRY_DSN secret. That value has been empty in released binaries since around v1.10, so crash reporting has effectively been disabled, and it cannot work at all for from-source builds such as Homebrew Core. A Sentry DSN is a public, write-only key that is safe to ship inside client binaries, so this hardcodes it as the default. The build-time injection is removed from the release pipeline so every build path (releases, Homebrew Core, and plain go build) reports to Sentry consistently. * Skip Sentry reporting for local/dev builds Reporting now keys off buildinfo.Version instead of the Sentry DSN. Local builds stamp the version as "dev" (and a plain go build leaves it empty), so ReportException returns early for those and panics re-panic with a real stack trace. Release and Homebrew Core builds carry a real version and continue to report.
1 parent d867b4c commit 161017a

4 files changed

Lines changed: 80 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jobs:
3535
workdir: 'auth0-cli'
3636
env:
3737
GITHUB_TOKEN: ${{ github.token }}
38-
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
3938

4039
# Homebrew Tap Process
4140
- name: Checkout Homebrew Tap Repo

.goreleaser.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ builds:
1717
- -X 'github.com/auth0/auth0-cli/internal/buildinfo.Revision={{.Commit}}'
1818
- -X 'github.com/auth0/auth0-cli/internal/buildinfo.BuildUser=goreleaser'
1919
- -X 'github.com/auth0/auth0-cli/internal/buildinfo.BuildDate={{.Date}}'
20-
- -X 'github.com/auth0/auth0-cli/internal/instrumentation.SentryDSN={{.Env.SENTRY_DSN}}'
2120
archives:
2221
- name_template: '{{ .ProjectName }}_{{ .Version }}_{{ title .Os }}_{{ if eq .Arch "arm64" }}arm64{{ else }}x86_64{{ end }}'
2322
files:

internal/instrumentation/instrumentation.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ import (
55
"time"
66

77
"github.com/getsentry/sentry-go"
8+
9+
"github.com/auth0/auth0-cli/internal/buildinfo"
810
)
911

10-
var SentryDSN string
12+
// SentryDSN is the destination for crash reports. A Sentry DSN is a public,
13+
// write-only key that is safe to ship inside client binaries, so we hardcode a
14+
// default here. This ensures crash reporting works for builds that are not
15+
// produced by our release pipeline (for example Homebrew Core, which builds
16+
// from source and cannot inject build-time values). Release builds may still
17+
// override this via ldflags.
18+
var SentryDSN = "https://370df87d33df46cb90182dd80a50fdc4@o27592.ingest.sentry.io/5694458"
1119

1220
// ReportException is designed to be called once as the CLI exits. We're
1321
// purposefully initializing a client all the time given this context.
@@ -16,6 +24,15 @@ func ReportException(err error) bool {
1624
return false
1725
}
1826

27+
// Skip crash reporting for local/development builds so that dev-time panics
28+
// and errors are not shipped to Sentry. Release pipelines (goreleaser and
29+
// Homebrew Core) stamp a real semantic version via ldflags, whereas a local
30+
// `make build`/`make install` stamps "dev" and a plain `go build` leaves it
31+
// empty.
32+
if buildinfo.Version == "" || buildinfo.Version == "dev" {
33+
return false
34+
}
35+
1936
if err := sentry.Init(sentry.ClientOptions{Dsn: SentryDSN}); err != nil {
2037
return false
2138
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package instrumentation
2+
3+
import (
4+
"errors"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
9+
"github.com/auth0/auth0-cli/internal/buildinfo"
10+
)
11+
12+
func TestReportException(t *testing.T) {
13+
tests := []struct {
14+
name string
15+
sentryDSN string
16+
version string
17+
want bool
18+
}{
19+
{
20+
name: "skips when Sentry DSN is empty",
21+
sentryDSN: "",
22+
version: "1.32.0",
23+
want: false,
24+
},
25+
{
26+
name: "skips for a plain go build with no version",
27+
sentryDSN: "https://public@o0.ingest.sentry.io/0",
28+
version: "",
29+
want: false,
30+
},
31+
{
32+
name: "skips for a local dev build",
33+
sentryDSN: "https://public@o0.ingest.sentry.io/0",
34+
version: "dev",
35+
want: false,
36+
},
37+
{
38+
name: "reports for a real release build",
39+
sentryDSN: "https://public@o0.ingest.sentry.io/0",
40+
version: "1.32.0",
41+
want: true,
42+
},
43+
}
44+
45+
originalDSN := SentryDSN
46+
originalVersion := buildinfo.Version
47+
t.Cleanup(func() {
48+
SentryDSN = originalDSN
49+
buildinfo.Version = originalVersion
50+
})
51+
52+
for _, test := range tests {
53+
t.Run(test.name, func(t *testing.T) {
54+
SentryDSN = test.sentryDSN
55+
buildinfo.Version = test.version
56+
57+
got := ReportException(errors.New("boom"))
58+
59+
assert.Equal(t, test.want, got)
60+
})
61+
}
62+
}

0 commit comments

Comments
 (0)