sentry.go 796 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package alerter
  2. import (
  3. "context"
  4. "github.com/getsentry/sentry-go"
  5. )
  6. type SentryAlerter struct {
  7. client *sentry.Client
  8. }
  9. func noIntegrations(ints []sentry.Integration) []sentry.Integration {
  10. return []sentry.Integration{}
  11. }
  12. func NewSentryAlerter(sentryDSN string) (*SentryAlerter, error) {
  13. sentryClient, err := sentry.NewClient(sentry.ClientOptions{
  14. Dsn: sentryDSN,
  15. AttachStacktrace: true,
  16. Integrations: noIntegrations,
  17. })
  18. if err != nil {
  19. return nil, err
  20. }
  21. return &SentryAlerter{
  22. client: sentryClient,
  23. }, nil
  24. }
  25. func (s *SentryAlerter) SendAlert(ctx context.Context, err error, data map[string]interface{}) {
  26. scope := sentry.NewScope()
  27. scope.SetExtras(data)
  28. s.client.CaptureException(
  29. err,
  30. &sentry.EventHint{
  31. Data: data,
  32. },
  33. scope,
  34. )
  35. }