Skip to content

Commit

Permalink
feat: add NewWithHub function to utilize existing Sentry hub
Browse files Browse the repository at this point in the history
  • Loading branch information
Saleh Saeed committed Nov 8, 2023
1 parent 76f3772 commit 221cdc6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package zlogsentry

import (
"crypto/x509"
"errors"
"io"
"net/http"
"time"
Expand Down Expand Up @@ -355,6 +356,29 @@ func New(dsn string, opts ...WriterOption) (*Writer, error) {
}, nil
}

// NewWithHub creates a writer using an existing sentry Hub and options.
func NewWithHub(hub *sentry.Hub, opts ...WriterOption) (*Writer, error) {
if hub == nil {
return nil, errors.New("hub cannot be nil")
}

cfg := newDefaultConfig()
for _, opt := range opts {
opt.apply(&cfg)
}

levels := make(map[zerolog.Level]struct{}, len(cfg.levels))
for _, lvl := range cfg.levels {
levels[lvl] = struct{}{}
}

return &Writer{
hub: hub,
levels: levels,
flushTimeout: cfg.flushTimeout,
}, nil
}

func newDefaultConfig() config {
return config{
levels: []zerolog.Level{
Expand Down

0 comments on commit 221cdc6

Please sign in to comment.