Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mention origin repo
  • Loading branch information
ribice committed Jan 25, 2025
commit a928aa783e7be76c012c52927935ecb766d9459c
2 changes: 2 additions & 0 deletions zap/sentryzap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"go.uber.org/zap/zapcore"
)

// This implementation is largely adapted from https://github.com/TheZeroSlave/zapsentry

const (
defaultMaxBreadcrumbs = 100
maxErrorDepth = 10
Expand All @@ -31,12 +33,12 @@
}

// NewSentryClientFromDSN creates a new Sentry client factory that uses the provided DSN.
func NewSentryClientFromDSN(dsn string) SentryClientFactory {
return func() (*sentry.Client, error) {
return sentry.NewClient(sentry.ClientOptions{
Dsn: dsn,
})
}

Check warning on line 41 in zap/sentryzap.go

View check run for this annotation

Codecov / codecov/patch

zap/sentryzap.go#L36-L41

Added lines #L36 - L41 were not covered by tests
}

// NewSentryClientFromClient creates a new Sentry client factory that returns the provided client.
Expand All @@ -50,25 +52,25 @@
type SentryClientFactory func() (*sentry.Client, error)

// NewScopeFromScope creates a new zapcore.Field that holds the provided Sentry scope.
func NewScopeFromScope(scope *sentry.Scope) zapcore.Field {
return zapcore.Field{
Key: sentryZapScopeKey,
Type: zapcore.SkipType,
Interface: scope,
}

Check warning on line 60 in zap/sentryzap.go

View check run for this annotation

Codecov / codecov/patch

zap/sentryzap.go#L55-L60

Added lines #L55 - L60 were not covered by tests
}

// NewScope creates a new zapcore.Field that holds a new Sentry scope.
func NewScope() zapcore.Field {
return NewScopeFromScope(sentry.NewScope())

Check warning on line 65 in zap/sentryzap.go

View check run for this annotation

Codecov / codecov/patch

zap/sentryzap.go#L64-L65

Added lines #L64 - L65 were not covered by tests
}

// NewCore creates a new zapcore.Core that sends logs to Sentry.
func NewCore(cfg Configuration, factory SentryClientFactory) (zapcore.Core, error) {
client, err := factory()
if err != nil {
return zapcore.NewNopCore(), fmt.Errorf("failed to create Sentry client: %w", err)
}

Check warning on line 73 in zap/sentryzap.go

View check run for this annotation

Codecov / codecov/patch

zap/sentryzap.go#L72-L73

Added lines #L72 - L73 were not covered by tests

setDefaultConfig(&cfg)

Expand Down
Loading