File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
166167type 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
181183func (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 {
@@ -198,6 +203,7 @@ func (h *eventHandler) WithAttrs(attrs []slog.Attr) *eventHandler {
198203 copy (groupsCopy , h .groups )
199204
200205 return & eventHandler {
206+ ctx : h .ctx ,
201207 option : h .option ,
202208 attrs : appendAttrsToGroup (h .groups , h .attrs , attrs ... ),
203209 groups : groupsCopy ,
@@ -215,6 +221,7 @@ func (h *eventHandler) WithGroup(name string) *eventHandler {
215221 newGroups = append (newGroups , name )
216222
217223 return & eventHandler {
224+ ctx : h .ctx ,
218225 option : h .option ,
219226 attrs : h .attrs ,
220227 groups : newGroups ,
You can’t perform that action at this time.
0 commit comments