-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: report bug to sentry (#4328) (cherry picked from commit 0adabfd) # Conflicts: # go.mod # ignite/internal/analytics/analytics.go * updates * fix cl --------- Co-authored-by: Julien Robert <[email protected]>
- Loading branch information
1 parent
ddefc2e
commit fa8078a
Showing
7 changed files
with
105 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package sentry | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/getsentry/sentry-go" | ||
|
||
"github.com/ignite/cli/v28/ignite/pkg/errors" | ||
"github.com/ignite/cli/v28/ignite/version" | ||
) | ||
|
||
const IgniteDNS = "https://bugs.ignite.com" | ||
|
||
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, errors.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, errors.Errorf("failed to init sentry: %w", err) | ||
} | ||
|
||
return func() { | ||
sentry.Recover() | ||
sentry.Flush(time.Second * 2) | ||
}, nil | ||
} | ||
|
||
func getEnvironment(igniteVersion string) string { | ||
if strings.Contains(igniteVersion, "dev") { | ||
return "development" | ||
} | ||
|
||
return "production" | ||
} |