Skip to content

Commit

Permalink
Merge pull request #18 from smurfpandey/patch-1
Browse files Browse the repository at this point in the history
Added Flush method send all events before app is exited
  • Loading branch information
onrik committed Jul 15, 2020
2 parents 477746d + 303a93f commit e6c4479
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions sentry/sentry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sentry

import (
"time"

"github.com/getsentry/sentry-go"
"github.com/sirupsen/logrus"
)
Expand All @@ -20,12 +22,13 @@ var (
type Options sentry.ClientOptions

type Hook struct {
client *sentry.Client
levels []logrus.Level
tags map[string]string
release string
environment string
prefix string
client *sentry.Client
levels []logrus.Level
tags map[string]string
release string
environment string
prefix string
flushTimeout time.Duration
}

func (hook *Hook) Levels() []logrus.Level {
Expand Down Expand Up @@ -83,16 +86,25 @@ func (hook *Hook) SetEnvironment(environment string) {
hook.environment = environment
}

func (hook *Hook) SetFlushTimeout(timeout time.Duration) {
hook.flushTimeout = timeout
}

func (hook *Hook) Flush() {
hook.client.Flush(hook.flushTimeout)
}

func NewHook(options Options, levels ...logrus.Level) (*Hook, error) {
client, err := sentry.NewClient(sentry.ClientOptions(options))
if err != nil {
return nil, err
}

hook := Hook{
client: client,
levels: levels,
tags: map[string]string{},
client: client,
levels: levels,
tags: map[string]string{},
flushTimeout: 10 * time.Second,
}
if len(hook.levels) == 0 {
hook.levels = logrus.AllLevels
Expand Down

0 comments on commit e6c4479

Please sign in to comment.