-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apptracker: Error tracking interface and it's Sentry implementation (#34
) What Error tracking interface and it's Sentry implementation Task: https://app.asana.com/0/1207947010297920/1207245825676510 Why Adding sentry tracking to the Wallet Backend
- Loading branch information
1 parent
6a76d65
commit a74bc67
Showing
19 changed files
with
356 additions
and
88 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,6 @@ | ||
package apptracker | ||
|
||
type AppTracker interface { | ||
CaptureMessage(message string) // Send a message to the app tracker | ||
CaptureException(exception error) // Send an exception to the app tracker | ||
} |
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,19 @@ | ||
package apptracker | ||
|
||
import ( | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type MockAppTracker struct { | ||
mock.Mock | ||
} | ||
|
||
var _ AppTracker = (*MockAppTracker)(nil) | ||
|
||
func (sv *MockAppTracker) CaptureMessage(message string) { | ||
sv.Called(message) | ||
} | ||
|
||
func (sv *MockAppTracker) CaptureException(exception error) { | ||
sv.Called(exception) | ||
} |
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,40 @@ | ||
package sentry | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/getsentry/sentry-go" | ||
) | ||
|
||
// We need these variables to be able to mock sentry.CaptureMessage and sentry.CaptureException in tests since | ||
// package level functions cannot be mocked | ||
var ( | ||
captureMessageFunc = sentry.CaptureMessage | ||
captureExceptionFunc = sentry.CaptureException | ||
InitFunc = sentry.Init | ||
FlushFunc = sentry.Flush | ||
RecoverFunc = sentry.Recover | ||
) | ||
|
||
type SentryTracker struct{} | ||
|
||
func (s *SentryTracker) CaptureMessage(message string) { | ||
captureMessageFunc(message) | ||
} | ||
|
||
func (s *SentryTracker) CaptureException(exception error) { | ||
captureExceptionFunc(exception) | ||
} | ||
|
||
func NewSentryTracker(dsn string, env string, flushFreq int) (*SentryTracker, error) { | ||
if err := InitFunc(sentry.ClientOptions{ | ||
Dsn: dsn, | ||
Environment: env, | ||
}); err != nil { | ||
return nil, err | ||
} | ||
defer FlushFunc(time.Second * time.Duration(flushFreq)) | ||
defer RecoverFunc() | ||
return &SentryTracker{}, nil | ||
|
||
} |
Oops, something went wrong.