From f1ee49abdb4f2a05e0da04490e4d3f322a190fc5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 29 Aug 2024 10:03:26 +0200 Subject: [PATCH 1/8] feat: report bug to sentry --- go.mod | 2 +- ignite/cmd/ignite/main.go | 7 ++-- ignite/internal/analytics/analytics.go | 26 +++++++++++++-- ignite/pkg/sentry/sentry.go | 46 ++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 ignite/pkg/sentry/sentry.go diff --git a/go.mod b/go.mod index 35c52b4040..1fddeea98e 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( github.com/cosmos/gogoproto v1.6.0 github.com/emicklei/proto v1.12.2 github.com/emicklei/proto-contrib v0.15.0 + github.com/getsentry/sentry-go v0.27.0 github.com/go-delve/delve v1.21.0 github.com/go-git/go-git/v5 v5.12.0 github.com/go-openapi/analysis v0.23.0 @@ -213,7 +214,6 @@ require ( github.com/firefart/nonamedreturns v1.0.5 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fzipp/gocyclo v0.6.0 // indirect - github.com/getsentry/sentry-go v0.27.0 // indirect github.com/ghostiam/protogetter v0.3.6 // indirect github.com/go-chi/chi/v5 v5.0.12 // indirect github.com/go-critic/go-critic v0.11.4 // indirect diff --git a/ignite/cmd/ignite/main.go b/ignite/cmd/ignite/main.go index 3b5236bb20..33b1dbd15f 100644 --- a/ignite/cmd/ignite/main.go +++ b/ignite/cmd/ignite/main.go @@ -19,12 +19,13 @@ import ( "github.com/ignite/cli/v29/ignite/pkg/xstrings" ) +const exitCodeOK, exitCodeError = 0, 1 + func main() { os.Exit(run()) } func run() int { - const exitCodeOK, exitCodeError = 0, 1 ctx := clictx.From(context.Background()) cmd, cleanUp, err := ignitecmd.New(ctx) if err != nil { @@ -41,6 +42,7 @@ func run() int { } var wg sync.WaitGroup analytics.SendMetric(&wg, subCmd) + analytics.SendErrors(&wg, ctx) err = cmd.ExecuteContext(ctx) if err != nil { @@ -77,7 +79,8 @@ func run() int { return exitCodeError } - wg.Wait() // waits for all metrics to be sent + // waits for analytics to finish + wg.Wait() return exitCodeOK } diff --git a/ignite/internal/analytics/analytics.go b/ignite/internal/analytics/analytics.go index 3858aa7117..c2227a2622 100644 --- a/ignite/internal/analytics/analytics.go +++ b/ignite/internal/analytics/analytics.go @@ -3,6 +3,7 @@ package analytics import ( "context" "encoding/json" + "fmt" "os" "path/filepath" "strconv" @@ -16,6 +17,7 @@ import ( "github.com/ignite/cli/v29/ignite/pkg/gitpod" "github.com/ignite/cli/v29/ignite/pkg/matomo" "github.com/ignite/cli/v29/ignite/pkg/randstr" + "github.com/ignite/cli/v29/ignite/pkg/sentry" "github.com/ignite/cli/v29/ignite/version" ) @@ -52,6 +54,7 @@ func SendMetric(wg *sync.WaitGroup, cmd *cobra.Command) { } dntInfo, err := checkDNT() + fmt.Println(dntInfo, err) if err != nil || dntInfo.DoNotTrack { return } @@ -99,11 +102,30 @@ func SendMetric(wg *sync.WaitGroup, cmd *cobra.Command) { }() } +// SendErrors send command errors to Sentry. +func SendErrors(wg *sync.WaitGroup, ctx context.Context) { + dntInfo, err := checkDNT() + if err != nil || dntInfo.DoNotTrack { + return + } + + closeSentry, err := sentry.InitSentry(ctx) + wg.Add(1) + go func() { + defer wg.Done() + if err == nil { + defer closeSentry() + } + }() +} + // checkDNT check if the user allow to track data or if the DO_NOT_TRACK // env var is set https://consoledonottrack.com/ func checkDNT() (anonIdentity, error) { - if dnt, err := strconv.ParseBool(os.Getenv(envDoNotTrack)); err != nil || dnt { - return anonIdentity{DoNotTrack: true}, nil + if dnt := os.Getenv(envDoNotTrack); dnt != "" { + if dnt, err := strconv.ParseBool(dnt); err != nil || dnt { + return anonIdentity{DoNotTrack: true}, nil + } } globalPath, err := config.DirPath() diff --git a/ignite/pkg/sentry/sentry.go b/ignite/pkg/sentry/sentry.go new file mode 100644 index 0000000000..ef3adc4c95 --- /dev/null +++ b/ignite/pkg/sentry/sentry.go @@ -0,0 +1,46 @@ +package sentry + +import ( + "context" + "fmt" + "strings" + "time" + + "github.com/getsentry/sentry-go" + + "github.com/ignite/cli/v29/ignite/version" +) + +const IgniteDNS = "https://examplePublicKey@o0.ingest.sentry.io/0" + +func InitSentry(ctx context.Context) (deferMe func(), err error) { + sentrySyncTransport := sentry.NewHTTPSyncTransport() + sentrySyncTransport.Timeout = time.Second * 3 + + igniteInfo, err := version.GetInfo(ctx) + if err != nil { + return nil, fmt.Errorf("failed to init sentry: %w", err) + } + + if err := sentry.Init(sentry.ClientOptions{ + Dsn: IgniteDNS, + Transport: sentrySyncTransport, + Environment: getEnvironment(igniteInfo.CLIVersion), + Release: fmt.Sprintf("ignite@%s", igniteInfo.CLIVersion), + SampleRate: 1.0, // get all events + }); err != nil { + return nil, fmt.Errorf("failed to init sentry: %w", err) + } + + return func() { + sentry.Flush(time.Second * 2) + }, nil +} + +func getEnvironment(igniteVersion string) string { + if strings.Contains(igniteVersion, "dev") { + return "development" + } else { + return "production" + } +} From 871f28a4f44d378cdefc7ba1fce67d3c626ea7c0 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 29 Aug 2024 10:07:42 +0200 Subject: [PATCH 2/8] add cl --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index c6eb124d2f..16ab1ec533 100644 --- a/changelog.md +++ b/changelog.md @@ -38,6 +38,7 @@ - [#4290](https://github.com/ignite/cli/pull/4290) Remove ignite ics logic from ignite cli (this functionality will be in the `consumer` app) - [#4295](https://github.com/ignite/cli/pull/4295) Stop scaffolding `pulsar` files - [#4317](https://github.com/ignite/cli/pull/4317) Remove xchisel dependency +- [#4328](https://github.com/ignite/cli/pull/4328) Send ignite bug report to sentry. Opt out the same way as for usage analytics ### Fixes From cfcaf9a18e91a4140fcf40d6293c064692db956b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 12 Sep 2024 14:35:31 +0200 Subject: [PATCH 3/8] update sentry dns --- ignite/pkg/sentry/sentry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/pkg/sentry/sentry.go b/ignite/pkg/sentry/sentry.go index ef3adc4c95..a40e561d89 100644 --- a/ignite/pkg/sentry/sentry.go +++ b/ignite/pkg/sentry/sentry.go @@ -11,7 +11,7 @@ import ( "github.com/ignite/cli/v29/ignite/version" ) -const IgniteDNS = "https://examplePublicKey@o0.ingest.sentry.io/0" +const IgniteDNS = "https://bugs.ignite.com" func InitSentry(ctx context.Context) (deferMe func(), err error) { sentrySyncTransport := sentry.NewHTTPSyncTransport() From b4127b31f73ebbcc76e6ae18972630726d60f63c Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 12 Sep 2024 15:31:34 +0200 Subject: [PATCH 4/8] updates --- ignite/cmd/ignite/main.go | 2 +- ignite/internal/analytics/analytics.go | 6 ++--- ignite/pkg/errors/xerrors.go | 33 ++++++++++++++++++++------ ignite/pkg/sentry/sentry.go | 1 + 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/ignite/cmd/ignite/main.go b/ignite/cmd/ignite/main.go index 33b1dbd15f..dfeb9a600e 100644 --- a/ignite/cmd/ignite/main.go +++ b/ignite/cmd/ignite/main.go @@ -42,7 +42,7 @@ func run() int { } var wg sync.WaitGroup analytics.SendMetric(&wg, subCmd) - analytics.SendErrors(&wg, ctx) + analytics.EnableSentry(&wg, ctx) err = cmd.ExecuteContext(ctx) if err != nil { diff --git a/ignite/internal/analytics/analytics.go b/ignite/internal/analytics/analytics.go index c2227a2622..131c895f09 100644 --- a/ignite/internal/analytics/analytics.go +++ b/ignite/internal/analytics/analytics.go @@ -3,7 +3,6 @@ package analytics import ( "context" "encoding/json" - "fmt" "os" "path/filepath" "strconv" @@ -54,7 +53,6 @@ func SendMetric(wg *sync.WaitGroup, cmd *cobra.Command) { } dntInfo, err := checkDNT() - fmt.Println(dntInfo, err) if err != nil || dntInfo.DoNotTrack { return } @@ -102,8 +100,8 @@ func SendMetric(wg *sync.WaitGroup, cmd *cobra.Command) { }() } -// SendErrors send command errors to Sentry. -func SendErrors(wg *sync.WaitGroup, ctx context.Context) { +// EnableSentry enable errors reporting to Sentry. +func EnableSentry(wg *sync.WaitGroup, ctx context.Context) { dntInfo, err := checkDNT() if err != nil || dntInfo.DoNotTrack { return diff --git a/ignite/pkg/errors/xerrors.go b/ignite/pkg/errors/xerrors.go index 0ec5ce9728..66ba2c074e 100644 --- a/ignite/pkg/errors/xerrors.go +++ b/ignite/pkg/errors/xerrors.go @@ -14,23 +14,45 @@ package errors import ( "github.com/cockroachdb/errors" + "github.com/getsentry/sentry-go" ) // New creates an error with a simple error message. // A stack trace is retained. -func New(msg string) error { return errors.New(msg) } +func New(msg string) error { + err := errors.New(msg) + sentry.CaptureException(err) + return err +} // Errorf aliases Newf(). -func Errorf(format string, args ...interface{}) error { return errors.Errorf(format, args...) } +func Errorf(format string, args ...interface{}) error { + err := errors.Errorf(format, args...) + sentry.CaptureException(err) + return err +} + +// WithStack annotates err with a stack trace at the point WithStack was called. +func WithStack(err error) error { + errWithStack := errors.WithStack(err) + sentry.CaptureException(errWithStack) + return errWithStack +} // Wrap wraps an error with a message prefix. A stack trace is retained. -func Wrap(err error, msg string) error { return errors.Wrap(err, msg) } +func Wrap(err error, msg string) error { + errWrap := errors.Wrap(err, msg) + sentry.CaptureException(errWrap) + return errWrap +} // Wrapf wraps an error with a formatted message prefix. A stack // trace is also retained. If the format is empty, no prefix is added, // but the extra arguments are still processed for reportable strings. func Wrapf(err error, format string, args ...interface{}) error { - return errors.Wrapf(err, format, args...) + errWrap := errors.Wrapf(err, format, args...) + sentry.CaptureException(errWrap) + return errWrap } // Unwrap accesses the direct cause of the error if any, otherwise @@ -52,6 +74,3 @@ func Is(err, reference error) bool { return errors.Is(err, reference) } // As(interface{}) bool such that As(target) returns true. As will panic if target // is not a non-nil pointer to a type which implements error or is of interface type. func As(err error, target interface{}) bool { return errors.As(err, target) } - -// WithStack annotates err with a stack trace at the point WithStack was called. -func WithStack(err error) error { return errors.WithStack(err) } diff --git a/ignite/pkg/sentry/sentry.go b/ignite/pkg/sentry/sentry.go index a40e561d89..ec449c1027 100644 --- a/ignite/pkg/sentry/sentry.go +++ b/ignite/pkg/sentry/sentry.go @@ -33,6 +33,7 @@ func InitSentry(ctx context.Context) (deferMe func(), err error) { } return func() { + sentry.Recover() sentry.Flush(time.Second * 2) }, nil } From a45f869f528c77d6c47bfa741c0ba35dfb0542c2 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 12 Sep 2024 20:59:39 +0200 Subject: [PATCH 5/8] use error pkgs --- ignite/pkg/sentry/sentry.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ignite/pkg/sentry/sentry.go b/ignite/pkg/sentry/sentry.go index ec449c1027..4c3cb4f084 100644 --- a/ignite/pkg/sentry/sentry.go +++ b/ignite/pkg/sentry/sentry.go @@ -8,6 +8,7 @@ import ( "github.com/getsentry/sentry-go" + "github.com/ignite/cli/v29/ignite/pkg/errors" "github.com/ignite/cli/v29/ignite/version" ) @@ -19,7 +20,7 @@ func InitSentry(ctx context.Context) (deferMe func(), err error) { igniteInfo, err := version.GetInfo(ctx) if err != nil { - return nil, fmt.Errorf("failed to init sentry: %w", err) + return nil, errors.Errorf("failed to init sentry: %w", err) } if err := sentry.Init(sentry.ClientOptions{ @@ -29,7 +30,7 @@ func InitSentry(ctx context.Context) (deferMe func(), err error) { Release: fmt.Sprintf("ignite@%s", igniteInfo.CLIVersion), SampleRate: 1.0, // get all events }); err != nil { - return nil, fmt.Errorf("failed to init sentry: %w", err) + return nil, errors.Errorf("failed to init sentry: %w", err) } return func() { From e12c8000966df17b4fe84c8021589aa2244f6df3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 12 Sep 2024 21:00:11 +0200 Subject: [PATCH 6/8] chore: sync changelog (#4355) --- changelog.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 5e3e7f3995..9a21604508 100644 --- a/changelog.md +++ b/changelog.md @@ -16,7 +16,6 @@ - [#4111](https://github.com/ignite/cli/pull/4111) Remove vuex generation - [#4113](https://github.com/ignite/cli/pull/4113) Generate chain config documentation automatically - [#4131](https://github.com/ignite/cli/pull/4131) Support `bytes` as data type in the `scaffold` commands -- [#4297](https://github.com/ignite/cli/pull/4297) Add in-place testnet creation command for apps. - [#4300](https://github.com/ignite/cli/pull/4300) Only panics the module in the most top function level - [#4327](https://github.com/ignite/cli/pull/4327) Use the TxConfig from simState instead create a new one - [#4326](https://github.com/ignite/cli/pull/4326) fAdd `buf.build` version to `ignite version` command @@ -40,8 +39,6 @@ - [#4189](https://github.com/ignite/cli/pull/4189) Deprecate `ignite node` for `ignite connect` app - [#4290](https://github.com/ignite/cli/pull/4290) Remove ignite ics logic from ignite cli (this functionality will be in the `consumer` app) - [#4295](https://github.com/ignite/cli/pull/4295) Stop scaffolding `pulsar` files -- [#4322](https://github.com/ignite/cli/pull/4322) Create a message for authenticate buf for generate ts-client -- [#4319](https://github.com/ignite/cli/pull/4319) Remove fee abstraction module from open api code generation - [#4317](https://github.com/ignite/cli/pull/4317) Remove xchisel dependency - [#4328](https://github.com/ignite/cli/pull/4328) Send ignite bug report to sentry. Opt out the same way as for usage analytics - [#4341](https://github.com/ignite/cli/pull/4341) Bump `ibc-go` to `8.5.0` @@ -52,7 +49,24 @@ - [#4000](https://github.com/ignite/cli/pull/4000) Run all dry runners before the wet run in the `xgenny` pkg - [#4091](https://github.com/ignite/cli/pull/4091) Fix race conditions in the plugin logic - [#4128](https://github.com/ignite/cli/pull/4128) Check for duplicate proto fields in config + +## [`v28.5.2`](https://github.com/ignite/cli/releases/tag/v28.5.2) + +### Features + +- [#4297](https://github.com/ignite/cli/pull/4297) Add in-place testnet creation command for apps. + +### Changes + +- [#4292](https://github.com/ignite/cli/pull/4292) Bump Cosmos SDK to `v0.50.9` +- [#4341](https://github.com/ignite/cli/pull/4341) Bump `ibc-go` to `8.5.0` +- [#4345](https://github.com/ignite/cli/pull/4345) Added survey link + +### Fixes + +- [#4319](https://github.com/ignite/cli/pull/4319) Remove fee abstraction module from open api code generation - [#4309](https://github.com/ignite/cli/pull/4309) Fix chain id for chain simulations +- [#4322](https://github.com/ignite/cli/pull/4322) Create a message for authenticate buf for generate ts-client - [#4323](https://github.com/ignite/cli/pull/4323) Add missing `--config` handling in the `chain` commands - [#4350](https://github.com/ignite/cli/pull/4350) Skip upgrade prefix for sim tests From d0768cfb8c920f051c2fe2a6d7229a5ca3cec0ab Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 12 Sep 2024 21:01:05 +0200 Subject: [PATCH 7/8] updates --- changelog.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/changelog.md b/changelog.md index 9a21604508..d4050f4590 100644 --- a/changelog.md +++ b/changelog.md @@ -41,8 +41,6 @@ - [#4295](https://github.com/ignite/cli/pull/4295) Stop scaffolding `pulsar` files - [#4317](https://github.com/ignite/cli/pull/4317) Remove xchisel dependency - [#4328](https://github.com/ignite/cli/pull/4328) Send ignite bug report to sentry. Opt out the same way as for usage analytics -- [#4341](https://github.com/ignite/cli/pull/4341) Bump `ibc-go` to `8.5.0` -- [#4345](https://github.com/ignite/cli/pull/4345) Added survey link ### Fixes From 6328127070cf6e612655afc96fb84126ba160a0b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 13 Sep 2024 10:17:43 +0200 Subject: [PATCH 8/8] updates --- ignite/pkg/sentry/sentry.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ignite/pkg/sentry/sentry.go b/ignite/pkg/sentry/sentry.go index 4c3cb4f084..3189324291 100644 --- a/ignite/pkg/sentry/sentry.go +++ b/ignite/pkg/sentry/sentry.go @@ -42,7 +42,7 @@ func InitSentry(ctx context.Context) (deferMe func(), err error) { func getEnvironment(igniteVersion string) string { if strings.Contains(igniteVersion, "dev") { return "development" - } else { - return "production" } + + return "production" }