Skip to content

Commit

Permalink
Merge pull request #6 from ezr-ondrej/use_hub
Browse files Browse the repository at this point in the history
Use sentry sentry hub
  • Loading branch information
archdx authored Mar 9, 2023
2 parents 2ff7d3d + 02e53b5 commit 62cc923
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var now = time.Now

// Writer is a sentry events writer with std io.Writer iface.
type Writer struct {
client *sentry.Client
hub *sentry.Hub

levels map[zerolog.Level]struct{}
flushTimeout time.Duration
Expand All @@ -35,10 +35,10 @@ type Writer struct {
func (w *Writer) Write(data []byte) (int, error) {
event, ok := w.parseLogEvent(data)
if ok {
w.client.CaptureEvent(event, nil, nil)
w.hub.CaptureEvent(event)
// should flush before os.Exit
if event.Level == sentry.LevelFatal {
w.client.Flush(w.flushTimeout)
w.hub.Flush(w.flushTimeout)
}
}

Expand All @@ -48,7 +48,7 @@ func (w *Writer) Write(data []byte) (int, error) {
// Close forces client to flush all pending events.
// Can be useful before application exits.
func (w *Writer) Close() error {
w.client.Flush(w.flushTimeout)
w.hub.Flush(w.flushTimeout)
return nil
}

Expand Down Expand Up @@ -241,7 +241,7 @@ func New(dsn string, opts ...WriterOption) (*Writer, error) {
}

return &Writer{
client: sentry.CurrentHub().Client(),
hub: sentry.CurrentHub(),
levels: levels,
flushTimeout: cfg.flushTimeout,
}, nil
Expand Down

0 comments on commit 62cc923

Please sign in to comment.