Skip to content
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

instrumentation: add telemetry around failures #207

Merged
merged 1 commit into from
Mar 27, 2021
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
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/goreleaser-action@v2.4.1
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