Skip to content

Commit

Permalink
cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Feb 11, 2024
1 parent f46cf33 commit e06a54a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func (o Option) NewSentryHandler() slog.Handler {
o.Level = slog.LevelDebug
}

if o.Converter == nil {
o.Converter = DefaultConverter
}

return &SentryHandler{
option: o,
attrs: []slog.Attr{},
Expand All @@ -48,19 +52,14 @@ func (h *SentryHandler) Enabled(_ context.Context, level slog.Level) bool {
}

func (h *SentryHandler) Handle(ctx context.Context, record slog.Record) error {
converter := DefaultConverter
if h.option.Converter != nil {
converter = h.option.Converter
}

hub := sentry.CurrentHub()
if hubFromContext := sentry.GetHubFromContext(ctx); hubFromContext != nil {
hub = hubFromContext
} else if h.option.Hub != nil {
hub = h.option.Hub
}

event := converter(h.option.AddSource, h.option.ReplaceAttr, h.attrs, h.groups, &record, hub)
event := h.option.Converter(h.option.AddSource, h.option.ReplaceAttr, h.attrs, h.groups, &record, hub)
hub.CaptureEvent(event)

return nil
Expand Down

0 comments on commit e06a54a

Please sign in to comment.