-
Notifications
You must be signed in to change notification settings - Fork 549
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf87ef0
commit 0adabfd
Showing
6 changed files
with
99 additions
and
10 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
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/v29/ignite/pkg/errors" | ||
"github.com/ignite/cli/v29/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" | ||
} |