Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

Commit 221cdc6

Browse files
author
Saleh Saeed
committed
feat: add NewWithHub function to utilize existing Sentry hub
1 parent 76f3772 commit 221cdc6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

writer.go

+24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package zlogsentry
22

33
import (
44
"crypto/x509"
5+
"errors"
56
"io"
67
"net/http"
78
"time"
@@ -355,6 +356,29 @@ func New(dsn string, opts ...WriterOption) (*Writer, error) {
355356
}, nil
356357
}
357358

359+
// NewWithHub creates a writer using an existing sentry Hub and options.
360+
func NewWithHub(hub *sentry.Hub, opts ...WriterOption) (*Writer, error) {
361+
if hub == nil {
362+
return nil, errors.New("hub cannot be nil")
363+
}
364+
365+
cfg := newDefaultConfig()
366+
for _, opt := range opts {
367+
opt.apply(&cfg)
368+
}
369+
370+
levels := make(map[zerolog.Level]struct{}, len(cfg.levels))
371+
for _, lvl := range cfg.levels {
372+
levels[lvl] = struct{}{}
373+
}
374+
375+
return &Writer{
376+
hub: hub,
377+
levels: levels,
378+
flushTimeout: cfg.flushTimeout,
379+
}, nil
380+
}
381+
358382
func newDefaultConfig() config {
359383
return config{
360384
levels: []zerolog.Level{

0 commit comments

Comments
 (0)