Skip to content

Commit 478a19a

Browse files
committed
fix: provide init ctx to eventHandler
1 parent 2d82e58 commit 478a19a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

slog/sentryslog.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func (o Option) NewSentryHandler(ctx context.Context) slog.Handler {
109109
logger.SetAttributes(attribute.String("sentry.origin", SlogOrigin))
110110

111111
eventHandler := &eventHandler{
112+
ctx: ctx,
112113
option: o,
113114
attrs: []slog.Attr{},
114115
groups: []string{},
@@ -164,6 +165,7 @@ func (h *SentryHandler) WithGroup(name string) slog.Handler {
164165
}
165166

166167
type eventHandler struct {
168+
ctx context.Context
167169
option Option
168170
attrs []slog.Attr
169171
groups []string
@@ -179,7 +181,10 @@ func (h *eventHandler) Enabled(_ context.Context, level slog.Level) bool {
179181
}
180182

181183
func (h *eventHandler) Handle(ctx context.Context, record slog.Record) error {
182-
hub := sentry.CurrentHub()
184+
hub := sentry.GetHubFromContext(h.ctx)
185+
if hub == nil {
186+
hub = sentry.CurrentHub()
187+
}
183188
if hubFromContext := sentry.GetHubFromContext(ctx); hubFromContext != nil {
184189
hub = hubFromContext
185190
} else if h.option.Hub != nil {

0 commit comments

Comments
 (0)