Skip to content

Commit

Permalink
instrumentation: add telemetry around failures (#207)
Browse files Browse the repository at this point in the history
This will start collecting errors. We can continue tweaking this, but
this will get us to the basics at least.

== In scope:
- Reporting the Go version
- Reporting the OS type
- Reproting the architecture (e.g. amd64)

== Out of scope:
- Discerning the different error types we have. For now, any errors will
  get sent.
  • Loading branch information
cyx authored Mar 27, 2021
1 parent 6d76fcb commit 703b67b
Show file tree
Hide file tree
Showing 36 changed files with 5,786 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ jobs:
with:
go-version: 1.16

- name: Prepare instrumentation
run: |
echo -n "$SENTRY_DSN" >> $GITHUB_WORKSPACE/internal/instrumentation/sentry_dsn
shell: bash
env:
SENTRY_DSN : ${{secrets.SENTRY_DSN}}

- name: Run GoReleaser
uses: goreleaser/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/briandowns/spinner v1.12.0
github.com/charmbracelet/glamour v0.2.0
github.com/fatih/color v1.10.0 // indirect
github.com/getsentry/sentry-go v0.10.0
github.com/golang/mock v1.5.0
github.com/golang/snappy v0.0.3 // indirect
github.com/google/go-cmp v0.5.5
Expand Down
123 changes: 118 additions & 5 deletions go.sum

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package cli

import (
"context"
"fmt"
"os"

"github.com/auth0/auth0-cli/internal/buildinfo"
"github.com/auth0/auth0-cli/internal/display"
"github.com/auth0/auth0-cli/internal/instrumentation"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -93,9 +95,18 @@ func Execute() {
// rootCmd.AddCommand(actionsCmd(cli))
// rootCmd.AddCommand(triggersCmd(cli))

defer func() {
if v := recover(); v != nil {
err := fmt.Errorf("panic: %v", v)
instrumentation.ReportException(err)
}
}()

if err := rootCmd.ExecuteContext(context.TODO()); err != nil {
cli.renderer.Heading("error")
cli.renderer.Errorf(err.Error())

instrumentation.ReportException(err)
os.Exit(1)
}
}
29 changes: 29 additions & 0 deletions internal/instrumentation/instrumentation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package instrumentation

import (
_ "embed"
"time"

"github.com/getsentry/sentry-go"
)

//go:embed sentrydsn.txt
var sentryDSN string

// ReportException is designed to be called once as the CLI exits. We're
// purposefully initializing a client all the time given this context.
func ReportException(err error) {
if sentryDSN == "" {
return
}

if err := sentry.Init(sentry.ClientOptions{Dsn: sentryDSN}); err != nil {
return
}

// Flush buffered events before the program terminates.
sentry.CaptureException(err)

// Allow up to 2s to flush, otherwise quit.
sentry.Flush(2 * time.Second)
}
Empty file.
18 changes: 18 additions & 0 deletions vendor/github.com/getsentry/sentry-go/.craft.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/getsentry/sentry-go/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions vendor/github.com/getsentry/sentry-go/.golangci.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 703b67b

Please sign in to comment.