Documentation
¶
Index ¶
- func WithSNSNotifier(notifier *SNSNotifier) interface{}
- type AlertConfig
- type CheckResult
- type CloudWatchLogsClient
- type HealthChecker
- type HealthStatus
- type LogBuffer
- type LogEntry
- type LogSink
- type LoggerConfig
- type LoggerConfigOption
- func WithAsyncLogging() LoggerConfigOption
- func WithBatchSize(size int) LoggerConfigOption
- func WithBufferSize(size int) LoggerConfigOption
- func WithCallerInfo() LoggerConfigOption
- func WithFlushInterval(interval time.Duration) LoggerConfigOption
- func WithFormat(format string) LoggerConfigOption
- func WithLogGroup(logGroup string) LoggerConfigOption
- func WithLogStream(logStream string) LoggerConfigOption
- func WithRetryConfig(maxRetries int, retryDelay time.Duration) LoggerConfigOption
- func WithStackTrace() LoggerConfigOption
- func WithTenantContext(tenantID, userID string) LoggerConfigOption
- type LoggerFactory
- type LoggerStats
- type MetricEntry
- type MetricsCollector
- type MetricsStats
- type ObservabilityProvider
- type SNSClient
- type SNSConfig
- type SNSNotificationMessage
- type SNSNotifier
- type StructuredLogger
- type TestObservabilityProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithSNSNotifier ¶ added in v1.0.30
func WithSNSNotifier(notifier *SNSNotifier) interface{}
WithSNSNotifier creates an option with the specified SNS notifier
Types ¶
type AlertConfig ¶ added in v1.0.30
type AlertConfig struct {
AlertType string `json:"alert_type"`
AlertTargetType string `json:"alert_target_type"`
}
AlertConfig contains alert configuration
type CheckResult ¶
type CheckResult struct {
Healthy bool `json:"healthy"`
Message string `json:"message,omitempty"`
Duration time.Duration `json:"duration"`
Error string `json:"error,omitempty"`
Critical bool `json:"critical"`
}
CheckResult represents the result of a single health check
type CloudWatchLogsClient ¶
type CloudWatchLogsClient interface {
CreateLogGroup(ctx context.Context, params *cloudwatchlogs.CreateLogGroupInput, optFns ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.CreateLogGroupOutput, error)
CreateLogStream(ctx context.Context, params *cloudwatchlogs.CreateLogStreamInput, optFns ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.CreateLogStreamOutput, error)
PutLogEvents(ctx context.Context, params *cloudwatchlogs.PutLogEventsInput, optFns ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.PutLogEventsOutput, error)
DescribeLogGroups(ctx context.Context, params *cloudwatchlogs.DescribeLogGroupsInput, optFns ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.DescribeLogGroupsOutput, error)
DescribeLogStreams(ctx context.Context, params *cloudwatchlogs.DescribeLogStreamsInput, optFns ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.DescribeLogStreamsOutput, error)
}
CloudWatchLogsClient defines the interface for CloudWatch Logs operations This interface allows for easy mocking and testing
type HealthChecker ¶
HealthChecker defines the interface for health checking
type HealthStatus ¶
type HealthStatus struct {
Healthy bool `json:"healthy"`
Checks map[string]CheckResult `json:"checks"`
Timestamp time.Time `json:"timestamp"`
Version string `json:"version,omitempty"`
}
HealthStatus represents the overall health status
type LogBuffer ¶
type LogBuffer interface {
Add(entry *LogEntry) error
Flush(ctx context.Context) error
Size() int
IsFull() bool
Clear()
Close() error
}
LogBuffer defines the interface for buffering log entries
type LogEntry ¶
type LogEntry struct {
Timestamp time.Time `json:"timestamp"`
Level string `json:"level"`
Message string `json:"message"`
Fields map[string]any `json:"fields,omitempty"`
RequestID string `json:"request_id,omitempty"`
TenantID string `json:"tenant_id,omitempty"`
UserID string `json:"user_id,omitempty"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
}
LogEntry represents a structured log entry with multi-tenant context
type LoggerConfig ¶
type LoggerConfig struct {
// Basic configuration
Level string `json:"level"`
Format string `json:"format"` // "json" or "console"
EnableCaller bool `json:"enable_caller"`
EnableStack bool `json:"enable_stack"`
// CloudWatch specific
LogGroup string `json:"log_group"`
LogStream string `json:"log_stream"`
BatchSize int `json:"batch_size"`
FlushInterval time.Duration `json:"flush_interval"`
BufferSize int `json:"buffer_size"`
// Performance tuning
AsyncLogging bool `json:"async_logging"`
MaxRetries int `json:"max_retries"`
RetryDelay time.Duration `json:"retry_delay"`
// Multi-tenant context
DefaultTenantID string `json:"default_tenant_id"`
DefaultUserID string `json:"default_user_id"`
}
LoggerConfig holds configuration for logger implementations
func NewDefaultLoggerConfig ¶ added in v1.0.29
func NewDefaultLoggerConfig(level string) LoggerConfig
NewDefaultLoggerConfig creates a LoggerConfig with sensible defaults for Lambda environments. It accepts a log level parameter and automatically configures CloudWatch log group and stream based on environment variables.
func NewLoggerConfigWithOptions ¶ added in v1.0.29
func NewLoggerConfigWithOptions(level string, opts ...LoggerConfigOption) LoggerConfig
NewLoggerConfigWithOptions creates a LoggerConfig with custom options while maintaining defaults. It accepts a log level and allows overriding specific configuration options.
type LoggerConfigOption ¶ added in v1.0.29
type LoggerConfigOption func(*LoggerConfig)
LoggerConfigOption is a functional option for customizing LoggerConfig
func WithAsyncLogging ¶ added in v1.0.29
func WithAsyncLogging() LoggerConfigOption
WithAsyncLogging enables async logging
func WithBatchSize ¶ added in v1.0.29
func WithBatchSize(size int) LoggerConfigOption
WithBatchSize sets a custom batch size
func WithBufferSize ¶ added in v1.0.29
func WithBufferSize(size int) LoggerConfigOption
WithBufferSize sets a custom buffer size
func WithCallerInfo ¶ added in v1.0.29
func WithCallerInfo() LoggerConfigOption
WithCallerInfo enables caller information in logs
func WithFlushInterval ¶ added in v1.0.29
func WithFlushInterval(interval time.Duration) LoggerConfigOption
WithFlushInterval sets a custom flush interval
func WithFormat ¶ added in v1.0.29
func WithFormat(format string) LoggerConfigOption
WithFormat sets the log format (json or console)
func WithLogGroup ¶ added in v1.0.29
func WithLogGroup(logGroup string) LoggerConfigOption
WithLogGroup sets a custom log group
func WithLogStream ¶ added in v1.0.29
func WithLogStream(logStream string) LoggerConfigOption
WithLogStream sets a custom log stream
func WithRetryConfig ¶ added in v1.0.29
func WithRetryConfig(maxRetries int, retryDelay time.Duration) LoggerConfigOption
WithRetryConfig sets retry configuration
func WithStackTrace ¶ added in v1.0.29
func WithStackTrace() LoggerConfigOption
WithStackTrace enables stack traces for errors
func WithTenantContext ¶ added in v1.0.29
func WithTenantContext(tenantID, userID string) LoggerConfigOption
WithTenantContext sets default tenant and user IDs
type LoggerFactory ¶
type LoggerFactory interface {
CreateConsoleLogger(config LoggerConfig) (StructuredLogger, error)
CreateCloudWatchLogger(config LoggerConfig, client CloudWatchLogsClient) (StructuredLogger, error)
CreateTestLogger() StructuredLogger
CreateNoOpLogger() StructuredLogger
}
LoggerFactory creates logger instances with different configurations
type LoggerStats ¶
type LoggerStats struct {
EntriesLogged int64 `json:"entries_logged"`
EntriesDropped int64 `json:"entries_dropped"`
FlushCount int64 `json:"flush_count"`
LastFlush time.Time `json:"last_flush"`
BufferSize int `json:"buffer_size"`
BufferCapacity int `json:"buffer_capacity"`
AverageFlushTime time.Duration `json:"average_flush_time"`
ErrorCount int64 `json:"error_count"`
LastError string `json:"last_error,omitempty"`
}
LoggerStats provides metrics about logger performance
type MetricEntry ¶
type MetricEntry struct {
Name string `json:"name"`
Value float64 `json:"value"`
Unit string `json:"unit"`
Timestamp time.Time `json:"timestamp"`
Tags map[string]string `json:"tags,omitempty"`
Fields map[string]any `json:"fields,omitempty"`
}
MetricEntry represents a metric data point
type MetricsCollector ¶
type MetricsCollector interface {
// Explicitly declare lift.MetricsCollector methods to avoid interface embedding issues
Counter(name string, tags ...map[string]string) lift.Counter
Histogram(name string, tags ...map[string]string) lift.Histogram
Gauge(name string, tags ...map[string]string) lift.Gauge
Flush() error
// Additional methods for enhanced functionality
RecordLatency(operation string, duration time.Duration)
RecordError(operation string)
RecordSuccess(operation string)
// Context methods
WithTags(tags map[string]string) MetricsCollector
WithTag(key, value string) MetricsCollector
// Batch operations
RecordBatch(entries []*MetricEntry) error
// Performance methods
Close() error
GetStats() MetricsStats
}
MetricsCollector extends the basic lift.MetricsCollector with additional functionality
type MetricsStats ¶
type MetricsStats struct {
MetricsRecorded int64 `json:"metrics_recorded"`
MetricsDropped int64 `json:"metrics_dropped"`
LastFlush time.Time `json:"last_flush"`
ErrorCount int64 `json:"error_count"`
LastError string `json:"last_error,omitempty"`
}
MetricsStats provides information about metrics collection
type ObservabilityProvider ¶
type ObservabilityProvider interface {
Logger() StructuredLogger
Metrics() MetricsCollector
HealthChecker() HealthChecker
Close() error
}
ObservabilityProvider combines logging, metrics, and health checking
type SNSClient ¶ added in v1.0.30
type SNSClient interface {
Publish(ctx context.Context, params *sns.PublishInput, optFns ...func(*sns.Options)) (*sns.PublishOutput, error)
}
SNSClient defines the interface for SNS operations This interface allows for easy mocking and testing
type SNSNotificationMessage ¶ added in v1.0.30
type SNSNotificationMessage struct {
AlertConfig AlertConfig `json:"alert_config"`
LogTime string `json:"log_time"`
Environment string `json:"environment,omitempty"`
Service string `json:"service,omitempty"`
Partner string `json:"partner"`
Stage string `json:"stage"`
AWSRegion string `json:"aws_region"`
AWSAccount string `json:"aws_account"`
Function string `json:"function"`
Subsystem string `json:"subsystem"`
Severity string `json:"severity"`
Message string `json:"message"`
}
SNSNotificationMessage represents the structure sent to SNS
type SNSNotifier ¶ added in v1.0.30
type SNSNotifier struct {
// contains filtered or unexported fields
}
SNSNotifier handles sending error notifications to AWS SNS
func NewSNSNotifier ¶ added in v1.0.30
func NewSNSNotifier(config SNSConfig) *SNSNotifier
NewSNSNotifier creates a new SNS notifier from configuration
func WithDefaultErrorNotifications ¶ added in v1.0.30
func WithDefaultErrorNotifications(snsClient SNSClient) *SNSNotifier
WithDefaultErrorNotifications creates an SNS notifier with default configuration It builds the SNS topic ARN using the standard Pay Theory format
func WithErrorNotifications ¶ added in v1.0.30
func WithErrorNotifications(snsClient SNSClient, topicARN string) *SNSNotifier
WithErrorNotifications creates an SNS notifier with the specified topic ARN
func (*SNSNotifier) GetTopicARN ¶ added in v1.0.30
func (n *SNSNotifier) GetTopicARN() string
GetTopicARN returns the configured SNS topic ARN
func (*SNSNotifier) NotifyError ¶ added in v1.0.30
func (n *SNSNotifier) NotifyError(ctx context.Context, logEntry *LogEntry) error
NotifyError sends an error notification to SNS when an error is logged
type StructuredLogger ¶
type StructuredLogger interface {
// Explicitly declare lift.Logger methods to avoid interface embedding issues
Debug(message string, fields ...map[string]any)
Info(message string, fields ...map[string]any)
Warn(message string, fields ...map[string]any)
Error(message string, fields ...map[string]any)
WithField(key string, value any) lift.Logger
WithFields(fields map[string]any) lift.Logger
// Context methods for multi-tenant logging
WithRequestID(requestID string) StructuredLogger
WithTenantID(tenantID string) StructuredLogger
WithUserID(userID string) StructuredLogger
WithTraceID(traceID string) StructuredLogger
WithSpanID(spanID string) StructuredLogger
// Performance and health methods
Flush(ctx context.Context) error
Close() error
IsHealthy() bool
GetStats() LoggerStats
}
StructuredLogger extends the basic lift.Logger with additional context methods
type TestObservabilityProvider ¶
type TestObservabilityProvider interface {
ObservabilityProvider
// Test-specific methods
GetLogEntries() []*LogEntry
GetMetricEntries() []*MetricEntry
ClearLogs()
ClearMetrics()
SimulateError(component string, err error)
GetCallCount(method string) int
}
TestObservabilityProvider provides test implementations