1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
package errortracking
import "github.com/getsentry/sentry-go"
// Tracker is an abstraction for error tracking.
type Tracker interface {
// Capture reports an error to the error reporting service
Capture(err error, opts ...CaptureOption)
}
var (
defaultTracker = newSentryTracker(sentry.CurrentHub())
)
// DefaultTracker returns the default global error tracker.
func DefaultTracker() Tracker {
return defaultTracker
}
// NewTracker constructs a new Tracker with the provided options.
func NewTracker(opts ...TrackerOption) (Tracker, error) {
client, err := sentry.NewClient(trackerOptionsToSentryClientOptions(opts...))
if err != nil {
return nil, err
}
hub := sentry.NewHub(client, sentry.NewScope())
return newSentryTracker(hub), nil
}
func trackerOptionsToSentryClientOptions(opts ...TrackerOption) sentry.ClientOptions {
config := applyTrackerOptions(opts)
return sentry.ClientOptions{
Dsn: config.sentryDSN,
Release: config.version,
Environment: config.sentryEnvironment,
}
}
|