sentry

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SensitiveFields = []string{
	"command", "cmd", "exec", "run", "query", "sql",
	"user", "username", "login", "email", "mail",
	"password", "passwd", "pwd", "pass", "secret",
	"token", "jwt", "bearer", "auth", "key",
	"path", "file", "filename", "filepath", "dir", "directory",
	"data", "payload", "body", "content", "message",
	"session", "session_id", "session_key",
	"encrypted", "encrypted_data", "cipher",
}

SensitiveFields contains field names that should be sanitized

View Source
var SensitivePatterns = struct {
	Command  *regexp.Regexp
	FilePath *regexp.Regexp
	Username *regexp.Regexp
	Email    *regexp.Regexp
	Token    *regexp.Regexp
	Key      *regexp.Regexp
	Password *regexp.Regexp
	HomeDir  *regexp.Regexp
	SQLQuery *regexp.Regexp
}{
	Command:  regexp.MustCompile(`(?i)(command|cmd|exec|run)[:=]\s*['""]?([^'""]+)['""]?`),
	FilePath: regexp.MustCompile(`(?i)(/home/[^/\s]+|/Users/[^/\s]+|C:\\Users\\[^\\]+|[A-Za-z]:\\Users\\[^\\]+)`),
	Username: regexp.MustCompile(`(?i)(user|username|login)[:=]\s*['""]?([^'""]+)['""]?`),
	Email:    regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}`),
	Token:    regexp.MustCompile(`(?i)(token|jwt|bearer|auth)[:=]\s*['""]?([a-zA-Z0-9._-]+)['""]?`),
	Key:      regexp.MustCompile(`(?i)(key|secret|password|pass)[:=]\s*['""]?([^'""]+)['""]?`),
	Password: regexp.MustCompile(`(?i)(password|passwd|pwd)[:=]\s*['""]?([^'""]+)['""]?`),
	HomeDir:  regexp.MustCompile(`(?i)(home|user).*?[/\\]([^/\\]+)[/\\]`),
	SQLQuery: regexp.MustCompile(`(?i)(select|insert|update|delete|create|drop|alter).*?from.*?`),
}

SensitivePatterns contains regex patterns for detecting sensitive information

Functions

func AddBreadcrumb

func AddBreadcrumb(category, message, level string, data map[string]interface{})

func CaptureError

func CaptureError(err error, component, operation string, tags ...map[string]string)

Convenience functions for global access

func CaptureMessage

func CaptureMessage(message, level, component, operation string, tags ...map[string]string)

func Close

func Close()

func Flush

func Flush(timeout time.Duration) bool

func Initialize

func Initialize(cfg *config.Config, version, commit, buildDate, author string) error

Initialize initializes the global Sentry manager

func IsEnabled

func IsEnabled() bool

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the Sentry client with CommandChronicles-specific functionality

func NewClient

func NewClient(cfg *config.Config, version, commit, buildDate, author string) (*Client, error)

NewClient creates a new Sentry client with safe configuration

func (*Client) AddBreadcrumb

func (c *Client) AddBreadcrumb(category, message, level string, data map[string]interface{})

AddBreadcrumb adds a safe breadcrumb for operation tracking

func (*Client) CaptureError

func (c *Client) CaptureError(err error, component, operation string, tags map[string]string)

CaptureError captures an error with safe context

func (*Client) CaptureMessage

func (c *Client) CaptureMessage(message, level, component, operation string, tags map[string]string)

CaptureMessage captures a message with safe context

func (*Client) Close

func (c *Client) Close()

Close closes the Sentry client

func (*Client) Flush

func (c *Client) Flush(timeout time.Duration) bool

Flush flushes pending events

func (*Client) GetSafeComponentContext

func (c *Client) GetSafeComponentContext(component, operation string) map[string]interface{}

GetSafeComponentContext returns safe context information for a component

func (*Client) GetSafeErrorMessage

func (c *Client) GetSafeErrorMessage(err error) string

GetSafeErrorMessage returns a safe version of an error message

func (*Client) IsEnabled

func (c *Client) IsEnabled() bool

IsEnabled returns whether Sentry monitoring is enabled

func (*Client) IsSensitiveError

func (c *Client) IsSensitiveError(err error) bool

IsSensitiveError checks if an error message contains sensitive information

func (*Client) WithContext

func (c *Client) WithContext(ctx context.Context) *Client

WithContext returns a new client with additional context

type ComponentReporter

type ComponentReporter struct {
	// contains filtered or unexported fields
}

ComponentReporter provides component-specific error reporting

func WithComponent

func WithComponent(component string) *ComponentReporter

func (*ComponentReporter) AddBreadcrumb

func (cr *ComponentReporter) AddBreadcrumb(message, level string, data map[string]interface{})

AddBreadcrumb adds a breadcrumb for this component

func (*ComponentReporter) CaptureError

func (cr *ComponentReporter) CaptureError(err error, operation string, tags ...map[string]string)

CaptureError captures an error for this component

func (*ComponentReporter) CaptureMessage

func (cr *ComponentReporter) CaptureMessage(message, level, operation string, tags ...map[string]string)

CaptureMessage captures a message for this component

func (*ComponentReporter) WithOperation

func (cr *ComponentReporter) WithOperation(operation string) *OperationReporter

WithOperation creates an operation-specific reporter

type Config

type Config struct {
	Enabled     bool    `toml:"enabled"`
	DSN         string  `toml:"dsn"`
	Environment string  `toml:"environment"`
	SampleRate  float64 `toml:"sample_rate"`
	Debug       bool    `toml:"debug"`
	Release     string  `toml:"release"`
}

Config contains Sentry-specific configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default Sentry configuration

type LoggerFactory

type LoggerFactory struct {
	// contains filtered or unexported fields
}

LoggerFactory creates loggers with Sentry integration

func NewLoggerFactory

func NewLoggerFactory(client *Client) *LoggerFactory

NewLoggerFactory creates a new logger factory

func (*LoggerFactory) CreateComponentLogger

func (f *LoggerFactory) CreateComponentLogger(baseLogger zerolog.Logger, component, operation string) *SentryLoggerAdapter

CreateComponentLogger creates a component-specific logger

func (*LoggerFactory) CreateLogger

func (f *LoggerFactory) CreateLogger(baseLogger zerolog.Logger, component string) *SentryLoggerAdapter

CreateLogger creates a new logger with Sentry integration

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager provides global access to Sentry functionality

func GetManager

func GetManager() *Manager

GetManager returns the global Sentry manager instance

func (*Manager) AddBreadcrumb

func (m *Manager) AddBreadcrumb(category, message, level string, data map[string]interface{})

AddBreadcrumb adds a breadcrumb for operation tracking

func (*Manager) CaptureError

func (m *Manager) CaptureError(err error, component, operation string, tags ...map[string]string)

CaptureError captures an error with safe context

func (*Manager) CaptureMessage

func (m *Manager) CaptureMessage(message, level, component, operation string, tags ...map[string]string)

CaptureMessage captures a message with safe context

func (*Manager) Close

func (m *Manager) Close()

Close closes the Sentry manager and client

func (*Manager) CreateComponentLogger

func (m *Manager) CreateComponentLogger(baseLogger zerolog.Logger, component, operation string) *SentryLoggerAdapter

CreateComponentLogger creates a component and operation specific logger

func (*Manager) CreateLogger

func (m *Manager) CreateLogger(baseLogger zerolog.Logger, component string) *SentryLoggerAdapter

CreateLogger creates a new logger with Sentry integration

func (*Manager) Flush

func (m *Manager) Flush(timeout time.Duration) bool

Flush flushes pending Sentry events

func (*Manager) IsEnabled

func (m *Manager) IsEnabled() bool

IsEnabled returns whether Sentry monitoring is enabled

func (*Manager) WithComponent

func (m *Manager) WithComponent(component string) *ComponentReporter

WithComponent creates a component-specific error reporter

type OperationReporter

type OperationReporter struct {
	// contains filtered or unexported fields
}

OperationReporter provides component and operation specific error reporting

func (*OperationReporter) AddBreadcrumb

func (or *OperationReporter) AddBreadcrumb(message, level string, data map[string]interface{})

AddBreadcrumb adds a breadcrumb for this component and operation

func (*OperationReporter) CaptureError

func (or *OperationReporter) CaptureError(err error, tags ...map[string]string)

CaptureError captures an error for this component and operation

func (*OperationReporter) CaptureMessage

func (or *OperationReporter) CaptureMessage(message, level string, tags ...map[string]string)

CaptureMessage captures a message for this component and operation

func (*OperationReporter) Failure

func (or *OperationReporter) Failure(err error, data map[string]interface{})

Failure marks the failure of an operation

func (*OperationReporter) Start

func (or *OperationReporter) Start()

Start marks the beginning of an operation

func (*OperationReporter) Success

func (or *OperationReporter) Success(data map[string]interface{})

Success marks the successful completion of an operation

type SentryLoggerAdapter

type SentryLoggerAdapter struct {
	// contains filtered or unexported fields
}

SentryLoggerAdapter wraps a zerolog.Logger with Sentry integration

func NewSentryLoggerAdapter

func NewSentryLoggerAdapter(logger zerolog.Logger, client *Client) *SentryLoggerAdapter

NewSentryLoggerAdapter creates a new logger adapter with Sentry integration

func (*SentryLoggerAdapter) AddBreadcrumb

func (s *SentryLoggerAdapter) AddBreadcrumb(category, message, level string, data map[string]interface{})

AddBreadcrumb adds a breadcrumb to Sentry

func (*SentryLoggerAdapter) CaptureError

func (s *SentryLoggerAdapter) CaptureError(err error, component, operation string)

CaptureError directly captures an error with context

func (*SentryLoggerAdapter) CaptureMessage

func (s *SentryLoggerAdapter) CaptureMessage(message, level, component, operation string)

CaptureMessage directly captures a message with context

func (*SentryLoggerAdapter) Close

func (s *SentryLoggerAdapter) Close()

Close closes the Sentry client

func (*SentryLoggerAdapter) Flush

func (s *SentryLoggerAdapter) Flush(timeout time.Duration) bool

Flush flushes pending Sentry events

func (*SentryLoggerAdapter) GetZerologLogger

func (s *SentryLoggerAdapter) GetZerologLogger() zerolog.Logger

GetZerologLogger returns the underlying zerolog logger

func (*SentryLoggerAdapter) WithComponent

func (s *SentryLoggerAdapter) WithComponent(component string) *SentryLoggerAdapter

WithComponent adds component context to the logger

func (*SentryLoggerAdapter) WithOperation

func (s *SentryLoggerAdapter) WithOperation(operation string) *SentryLoggerAdapter

WithOperation adds operation context to the logger

type ZerologHook

type ZerologHook struct {
	// contains filtered or unexported fields
}

ZerologHook implements zerolog.Hook to integrate Sentry with zerolog

func NewZerologHook

func NewZerologHook(client *Client, minLevel zerolog.Level) *ZerologHook

NewZerologHook creates a new zerolog hook for Sentry integration

func (*ZerologHook) Run

func (h *ZerologHook) Run(e *zerolog.Event, level zerolog.Level, msg string)

Run is called by zerolog for each log event

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL