Skip to content

Commit

Permalink
Merge pull request #13 from saleh199/add-new-with-hub
Browse files Browse the repository at this point in the history
feat: add NewWithHub function to utilize existing Sentry hub
  • Loading branch information
archdx authored Nov 9, 2023
2 parents 76f3772 + 221cdc6 commit 9a0b4be
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 9a0b4be

Please sign in to comment.