Documentation
¶
Overview ¶
Package sentry provides a Sentry integration sink for mtlog. It automatically tracks errors, captures stack traces, and provides breadcrumb support for production error monitoring.
Index ¶
- func BatchSpan(ctx context.Context, operation string, itemCount int, fn func() error) error
- func ContextsFromContext(ctx context.Context) map[string]interface{}
- func GetSpan(ctx context.Context) *sentry.Span
- func GetTransaction(ctx context.Context) *sentry.Span
- func MeasureSpan(ctx context.Context, operation string, fn func() error) error
- func RecordBreadcrumbInTransaction(ctx context.Context, breadcrumb sentry.Breadcrumb)
- func SetSpanData(ctx context.Context, key string, value interface{})
- func SetSpanStatus(ctx context.Context, status string)
- func SetSpanTag(ctx context.Context, key, value string)
- func StartSpan(ctx context.Context, operation string) (context.Context, func())
- func StartTransaction(ctx context.Context, name string, operation string) context.Context
- func TagsFromContext(ctx context.Context) map[string]string
- func TraceCache(ctx context.Context, operation, key string) (context.Context, func(hit bool))
- func TraceDatabaseQuery(ctx context.Context, query string, dbName string) (context.Context, func(error))
- func TraceHTTPRequest(ctx context.Context, method, url string) (context.Context, func(statusCode int))
- func TransactionMiddleware(name string) func(context.Context, func(context.Context) error) error
- func UserFromContext(ctx context.Context) (sentry.User, bool)
- func WithContext(ctx context.Context, key string, data interface{}) context.Context
- func WithSentry(dsn string, opts ...Option) (core.LogEventSink, error)
- func WithTags(ctx context.Context, tags map[string]string) context.Context
- func WithTransaction(ctx context.Context, name string, operation string) context.Context
- func WithUser(ctx context.Context, user sentry.User) context.Context
- type BreadcrumbBuffer
- type Fingerprinter
- type Metrics
- type Option
- func WithAdaptiveSampling(targetEPS uint64) Option
- func WithAttachStacktrace(attach bool) Option
- func WithBatchSize(size int) Option
- func WithBatchTimeout(timeout time.Duration) Option
- func WithBeforeSend(processor sentry.EventProcessor) Option
- func WithBreadcrumbLevel(level core.LogEventLevel) Option
- func WithBurstSampling(threshold uint64) Option
- func WithCustomSampling(sampler func(event *core.LogEvent) bool) Option
- func WithEnvironment(env string) Option
- func WithFingerprinter(f Fingerprinter) Option
- func WithGroupSampling(eventsPerGroup uint64, window time.Duration) Option
- func WithIgnoreErrors(errors ...error) Option
- func WithMaxBreadcrumbs(max int) Option
- func WithMetrics(enabled bool) Option
- func WithMetricsCallback(interval time.Duration, callback func(Metrics)) Option
- func WithMinLevel(level core.LogEventLevel) Option
- func WithPrioritySampling(baseRate float32) Option
- func WithRelease(release string) Option
- func WithRetry(maxRetries int, backoff time.Duration) Option
- func WithRetryJitter(jitter float64) Option
- func WithSampleRate(rate float64) Option
- func WithSampling(rate float32) Option
- func WithSamplingConfig(config *SamplingConfig) Option
- func WithSamplingProfile(profile SamplingProfile) Option
- func WithServerName(name string) Option
- func WithStackTraceCacheSize(size int) Option
- type SamplingConfig
- type SamplingProfile
- type SamplingStrategy
- type SentrySink
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextsFromContext ¶
ContextsFromContext extracts Sentry contexts from the context.
func GetTransaction ¶
GetTransaction retrieves the current transaction from context.
func MeasureSpan ¶
MeasureSpan measures the duration of an operation and records it as a span.
func RecordBreadcrumbInTransaction ¶
func RecordBreadcrumbInTransaction(ctx context.Context, breadcrumb sentry.Breadcrumb)
RecordBreadcrumbInTransaction adds a breadcrumb to the current transaction.
func SetSpanData ¶
SetSpanData sets data on the current span.
func SetSpanStatus ¶
SetSpanStatus sets the status of the current span.
func SetSpanTag ¶
SetSpanTag sets a tag on the current span.
func StartTransaction ¶
StartTransaction starts a new Sentry transaction and returns a context with it.
func TagsFromContext ¶
TagsFromContext extracts Sentry tags from the context.
func TraceCache ¶
TraceCache creates a span for cache operations.
func TraceDatabaseQuery ¶
func TraceDatabaseQuery(ctx context.Context, query string, dbName string) (context.Context, func(error))
TraceDatabaseQuery creates a span for a database query.
func TraceHTTPRequest ¶
func TraceHTTPRequest(ctx context.Context, method, url string) (context.Context, func(statusCode int))
TraceHTTPRequest creates a span for an HTTP request.
func TransactionMiddleware ¶
TransactionMiddleware wraps a handler with transaction tracking.
func UserFromContext ¶
UserFromContext extracts Sentry user information from the context.
func WithContext ¶
WithContext adds Sentry context data to the context.
func WithSentry ¶
func WithSentry(dsn string, opts ...Option) (core.LogEventSink, error)
WithSentry creates a new Sentry sink with the given DSN and options. This is a convenience function that returns a core.LogEventSink.
func WithTransaction ¶
WithTransaction creates a transaction-aware logger context.
Types ¶
type BreadcrumbBuffer ¶
type BreadcrumbBuffer struct {
// contains filtered or unexported fields
}
BreadcrumbBuffer is a thread-safe ring buffer for storing breadcrumbs. It automatically evicts old breadcrumbs based on age and capacity.
func NewBreadcrumbBuffer ¶
func NewBreadcrumbBuffer(maxSize int) *BreadcrumbBuffer
NewBreadcrumbBuffer creates a new breadcrumb buffer with the specified capacity.
func (*BreadcrumbBuffer) Add ¶
func (b *BreadcrumbBuffer) Add(breadcrumb sentry.Breadcrumb)
Add adds a breadcrumb to the buffer.
func (*BreadcrumbBuffer) Clear ¶
func (b *BreadcrumbBuffer) Clear()
Clear removes all breadcrumbs from the buffer.
func (*BreadcrumbBuffer) GetAll ¶
func (b *BreadcrumbBuffer) GetAll() []*sentry.Breadcrumb
GetAll returns all valid breadcrumbs in chronological order.
func (*BreadcrumbBuffer) SetMaxAge ¶
func (b *BreadcrumbBuffer) SetMaxAge(maxAge time.Duration)
SetMaxAge sets the maximum age for breadcrumbs.
func (*BreadcrumbBuffer) Size ¶
func (b *BreadcrumbBuffer) Size() int
Size returns the current number of breadcrumbs in the buffer.
type Fingerprinter ¶
Fingerprinter is a function that generates fingerprints for error grouping.
func ByErrorType ¶
func ByErrorType() Fingerprinter
ByErrorType groups by template and error type. This creates separate groups for different error types even if they have the same message template.
func ByMultipleProperties ¶
func ByMultipleProperties(propertyNames ...string) Fingerprinter
ByMultipleProperties groups by template and multiple property values. This allows for fine-grained grouping based on multiple dimensions.
func ByProperty ¶
func ByProperty(propertyName string) Fingerprinter
ByProperty groups by template and a specific property value. This is useful for grouping by user ID, tenant ID, or other identifiers.
func ByTemplate ¶
func ByTemplate() Fingerprinter
ByTemplate groups errors by message template only. This is useful when you want all instances of the same log message to be grouped together regardless of the actual values.
type Metrics ¶
type Metrics struct {
// Event statistics
EventsSent int64
EventsDropped int64
EventsFailed int64
EventsRetried int64
// Breadcrumb statistics
BreadcrumbsAdded int64
BreadcrumbsEvicted int64
// Batch statistics
BatchesSent int64
AverageBatchSize float64
// Performance metrics
LastFlushDuration time.Duration
TotalFlushTime time.Duration
// Network statistics
RetryCount int64
NetworkErrors int64
}
Metrics provides runtime statistics for the Sentry sink.
type Option ¶
type Option func(*SentrySink)
Option configures the Sentry sink.
func WithAdaptiveSampling ¶
WithAdaptiveSampling creates an adaptive sampling configuration
func WithAttachStacktrace ¶
WithAttachStacktrace enables stack trace attachment for all levels.
func WithBatchSize ¶
WithBatchSize sets the batch size for event sending.
func WithBatchTimeout ¶
WithBatchTimeout sets the timeout for batch sending.
func WithBeforeSend ¶
func WithBeforeSend(processor sentry.EventProcessor) Option
WithBeforeSend sets a function to modify or filter events before sending. Return nil to drop the event.
func WithBreadcrumbLevel ¶
func WithBreadcrumbLevel(level core.LogEventLevel) Option
WithBreadcrumbLevel sets the minimum level for breadcrumb collection. Events at or above this level but below MinLevel become breadcrumbs.
func WithBurstSampling ¶
WithBurstSampling creates a burst-aware sampling configuration
func WithCustomSampling ¶
WithCustomSampling uses a custom sampling function
func WithEnvironment ¶
WithEnvironment sets the environment (e.g., "production", "staging").
func WithFingerprinter ¶
func WithFingerprinter(f Fingerprinter) Option
WithFingerprinter sets a custom fingerprinting function for error grouping.
func WithGroupSampling ¶
WithGroupSampling enables per-error-group sampling
func WithIgnoreErrors ¶
WithIgnoreErrors configures errors to ignore.
func WithMaxBreadcrumbs ¶
WithMaxBreadcrumbs sets the maximum number of breadcrumbs to keep.
func WithMetrics ¶
WithMetrics enables or disables metrics collection.
func WithMetricsCallback ¶
WithMetricsCallback sets a callback that's called periodically with metrics.
func WithMinLevel ¶
func WithMinLevel(level core.LogEventLevel) Option
WithMinLevel sets the minimum level for events to be sent to Sentry. Events below this level may still be captured as breadcrumbs.
func WithPrioritySampling ¶
WithPrioritySampling creates a priority-based sampling configuration
func WithRetry ¶
WithRetry configures retry behavior for failed event submissions. maxRetries: maximum number of retry attempts (0 = no retries) backoff: base delay between retries (will be exponentially increased)
func WithRetryJitter ¶
WithRetryJitter sets the jitter factor for retry delays (0.0 to 1.0). Jitter helps prevent thundering herd problems.
func WithSampleRate ¶
WithSampleRate sets the sample rate (0.0 to 1.0).
func WithSampling ¶
WithSampling creates a basic fixed-rate sampling configuration
func WithSamplingConfig ¶
func WithSamplingConfig(config *SamplingConfig) Option
WithSamplingConfig applies a complete sampling configuration
func WithSamplingProfile ¶
func WithSamplingProfile(profile SamplingProfile) Option
WithSamplingProfile applies a predefined sampling profile
func WithStackTraceCacheSize ¶
WithStackTraceCacheSize sets the size of the stack trace cache. A larger cache can improve performance when the same errors occur repeatedly. Set to 0 to disable caching.
type SamplingConfig ¶
type SamplingConfig struct {
// Strategy defines the sampling approach
Strategy SamplingStrategy
// Rate is the base sampling rate (0.0 to 1.0)
Rate float32
// ErrorRate is the sampling rate for errors (defaults to 1.0)
ErrorRate float32
// FatalRate is the sampling rate for fatal events (defaults to 1.0)
FatalRate float32
// AdaptiveTargetEPS is the target events per second for adaptive sampling
AdaptiveTargetEPS uint64
// BurstThreshold is the events/sec threshold to trigger burst mode
BurstThreshold uint64
// CustomSampler is a function for custom sampling logic
CustomSampler func(event *core.LogEvent) bool
// GroupSampling enables sampling by error fingerprint/group
GroupSampling bool
// GroupSampleRate is events per group per time window
GroupSampleRate uint64
// GroupWindow is the time window for group sampling
GroupWindow time.Duration
}
SamplingConfig configures sampling behavior for the Sentry sink
func DefaultSamplingConfig ¶
func DefaultSamplingConfig() *SamplingConfig
DefaultSamplingConfig returns a sensible default sampling configuration
type SamplingProfile ¶
type SamplingProfile string
SamplingProfile represents a predefined sampling configuration
const ( // SamplingProfileDevelopment - verbose sampling for development SamplingProfileDevelopment SamplingProfile = "development" // SamplingProfileProduction - balanced sampling for production SamplingProfileProduction SamplingProfile = "production" // SamplingProfileHighVolume - aggressive sampling for high-volume apps SamplingProfileHighVolume SamplingProfile = "high-volume" // SamplingProfileCritical - minimal sampling, only critical events SamplingProfileCritical SamplingProfile = "critical" )
type SamplingStrategy ¶
type SamplingStrategy string
SamplingStrategy defines different sampling strategies for Sentry events
const ( // SamplingOff disables sampling - all events are sent SamplingOff SamplingStrategy = "off" // SamplingFixed uses a fixed rate for all events SamplingFixed SamplingStrategy = "fixed" // SamplingAdaptive adjusts rate based on volume SamplingAdaptive SamplingStrategy = "adaptive" // SamplingPriority samples based on event severity SamplingPriority SamplingStrategy = "priority" // SamplingBurst handles burst scenarios with backoff SamplingBurst SamplingStrategy = "burst" // SamplingCustom uses a custom sampling function SamplingCustom SamplingStrategy = "custom" )
type SentrySink ¶
type SentrySink struct {
// contains filtered or unexported fields
}
SentrySink sends log events to Sentry for error tracking and monitoring. It supports batching, breadcrumb collection, and custom fingerprinting.
func NewSentrySink ¶
func NewSentrySink(dsn string, opts ...Option) (*SentrySink, error)
NewSentrySink creates a new Sentry sink with the given DSN and options.
func (*SentrySink) Close ¶
func (s *SentrySink) Close() error
Close flushes any pending events and closes the sink.
func (*SentrySink) Emit ¶
func (s *SentrySink) Emit(event *core.LogEvent)
Emit sends a log event to Sentry.
func (*SentrySink) Metrics ¶
func (s *SentrySink) Metrics() Metrics
Metrics returns a snapshot of the current metrics.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
breadcrumbs
command
|
|
|
context
command
|
|
|
metrics
command
|
|
|
performance
command
|
|
|
retry
command
|
|
|
sampling
command
|