Documentation
¶
Overview ¶
Package sentryzap provides a zap Core implementation for sending logs to Sentry.
Index ¶
- Constants
- func Context(ctx context.Context) zapcore.Field
- type Option
- type SentryCore
- func (c *SentryCore) Check(entry zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
- func (c *SentryCore) Enabled(level zapcore.Level) bool
- func (c *SentryCore) Sync() error
- func (c *SentryCore) With(fields []zapcore.Field) zapcore.Core
- func (c *SentryCore) Write(entry zapcore.Entry, fields []zapcore.Field) error
Constants ¶
View Source
const (
// ZapOrigin is the Sentry origin attribute value for zap logs.
ZapOrigin = "auto.log.zap"
)
Variables ¶
This section is empty.
Functions ¶
func Context ¶
Context returns a zapcore.Field that can be used with logger.With() to link traces with the provided context. This allows propagating Sentry trace information from the context to logs without needing to pass a Hub.
Example:
logger := zap.New(sentryzap.NewSentryCore(ctx, sentryzap.Option{}))
logger = logger.With(sentryzap.Context(requestCtx))
logger.Info("handling request") // This log will be linked to the trace in requestCtx
Types ¶
type Option ¶
type Option struct {
// Level specifies the zap levels to capture and send to Sentry as log entries.
// Only logs at these specific levels will be processed.
// Defaults to all levels: Debug, Info, Warn, Error, DPanic, Panic, Fatal.
Level []zapcore.Level
// AddCaller includes caller information (file, line, function) in logs.
// Defaults to false.
AddCaller bool
// FlushTimeout specifies how long to wait when syncing/flushing logs.
// Defaults to 5 seconds.
FlushTimeout time.Duration
}
Option configures the Sentry zap Core.
type SentryCore ¶
type SentryCore struct {
// contains filtered or unexported fields
}
SentryCore is a zapcore.Core implementation that sends logs to Sentry.
func NewSentryCore ¶
func NewSentryCore(ctx context.Context, opts Option) *SentryCore
NewSentryCore creates a new zapcore.Core that sends logs to Sentry.
func (*SentryCore) Check ¶
func (c *SentryCore) Check(entry zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
Check determines whether the supplied Entry should be logged.
func (*SentryCore) Enabled ¶
func (c *SentryCore) Enabled(level zapcore.Level) bool
Enabled returns true if the given level is in the configured Level list.
func (*SentryCore) Sync ¶
func (c *SentryCore) Sync() error
Sync flushes any buffered log entries to Sentry.
Click to show internal directories.
Click to hide internal directories.