added delivery timeout

This commit is contained in:
Roberto Bampi 2014-11-06 21:17:29 +01:00
parent 8bbc74e9fb
commit 383ab1fb69
1 changed files with 15 additions and 1 deletions

View File

@ -1,10 +1,17 @@
package logrus_sentry
import (
"fmt"
"time"
"github.com/Sirupsen/logrus"
"github.com/getsentry/raven-go"
)
const (
timeout = 100 * time.Millisecond
)
var (
severityMap = map[logrus.Level]raven.Severity{
logrus.DebugLevel: raven.DEBUG,
@ -71,7 +78,14 @@ func (hook *SentryHook) Fire(entry *logrus.Entry) error {
}
packet.Extra = map[string]interface{}(d)
hook.client.Capture(packet, nil)
_, errCh := hook.client.Capture(packet, nil)
timeoutCh := time.After(timeout)
select {
case err := <-errCh:
return err
case <-timeoutCh:
return fmt.Errorf("no response from sentry server in %s", timeout)
}
return nil
}