Skip to content

Add Sentry integration sink #46

@willibrandon

Description

@willibrandon

Description:
Create Sentry sink for automatic error tracking and monitoring. Sentry is widely used in the Go ecosystem for production error monitoring.

Package: github.com/willibrandon/mtlog/adapters/sentry

Proposed API:

import mtlogsentry "github.com/willibrandon/mtlog/adapters/sentry"

logger := mtlog.New(
    mtlog.WithConsole(),
    mtlogsentry.WithSentry(
        "https://xxx@sentry.io/project",
        mtlogsentry.WithEnvironment("production"),
        mtlogsentry.WithRelease("v1.2.3"),
        mtlogsentry.WithSampling(0.1),
        mtlogsentry.WithMinLevel(core.ErrorLevel), // Only send errors by default
    ),
)

// Custom fingerprinting
mtlogsentry.WithFingerprinter(func(event *core.LogEvent) []string {
    // Custom logic to group similar errors
    return []string{event.MessageTemplate.Text, event.Properties["ErrorType"]}
})

Features:

  • Automatic error grouping/fingerprinting
  • Stack trace capture from error values
  • Breadcrumb support from lower level logs
  • Rate limiting and sampling
  • User context enrichment
  • Transaction/span integration
  • Release tracking
  • Environment tagging

Breadcrumb Collection:

// Info/Debug logs become breadcrumbs
logger.Debug("Connecting to database")
logger.Info("User {UserId} authenticated", userID)
// Error includes above as breadcrumbs in Sentry
logger.Error("Failed to process payment: {Error}", err)

Integration with Context:

// Attach user context
ctx = mtlogsentry.WithUser(ctx, sentryUser{
    ID: "user-123",
    Email: "user@example.com",
})
logger.WithContext(ctx).Error("Payment failed")

Implementation Notes:

  • Should batch events for efficiency
  • Cache stack traces to avoid recomputation
  • Only send ERROR and FATAL levels by default
  • Consider memory-bounded breadcrumb buffer
  • Support both DSN string and sentry.ClientOptions

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or requestobservabilityEnhancements that improve production observability and debugging capabilitiessinksChanges to log event sinks (output destinations)

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions