Documentation
¶
Index ¶
- Constants
- func BuiltInLoggingProfileNames() []string
- func EncodeLoggingProfileEvent(config LoggingProfileConfig, environment map[string]string, ...) (map[string]any, error)
- func EncodeLoggingProfileEventWithSanitizer(config LoggingProfileConfig, environment map[string]string, ...) (map[string]any, error)
- func HooksFromEMFMetricSink(sink *EMFMetricSink) apptheory.ObservabilityHooks
- func HooksFromLogger(logger StructuredLogger) apptheory.ObservabilityHooks
- func HooksFromLoggerAndEMFMetricSink(logger StructuredLogger, sink *EMFMetricSink) apptheory.ObservabilityHooks
- func LoggingProfileCatalog() map[string]any
- func LoggingProfileValidationErrors(config LoggingProfileConfig) []string
- func ValidateLoggingProfile(config LoggingProfileConfig) error
- type EMFMetricSink
- type EMFMetricSinkOption
- type ErrorNotifier
- type LogEntry
- type LoggerConfig
- type LoggerFactory
- type LoggerStats
- type LoggingProfileAlertingHints
- type LoggingProfileConfig
- type LoggingProfileEncoding
- type LoggingProfileEnrichment
- type LoggingProfileError
- type LoggingProfileErrorCapture
- type LoggingProfileEvent
- type LoggingProfileJobContext
- type LoggingProfileRequestContext
- type LoggingProfileSanitization
- type LoggingProfileValidationError
- type ProfileLogger
- func (l *ProfileLogger) Close() error
- func (l *ProfileLogger) Debug(message string, fields ...map[string]any)
- func (l *ProfileLogger) Entries() []map[string]any
- func (l *ProfileLogger) Error(message string, fields ...map[string]any)
- func (l *ProfileLogger) Flush(_ context.Context) error
- func (l *ProfileLogger) GetStats() LoggerStats
- func (l *ProfileLogger) Info(message string, fields ...map[string]any)
- func (l *ProfileLogger) IsHealthy() bool
- func (l *ProfileLogger) Warn(message string, fields ...map[string]any)
- func (l *ProfileLogger) WithField(key string, value any) StructuredLogger
- func (l *ProfileLogger) WithFields(fields map[string]any) StructuredLogger
- func (l *ProfileLogger) WithRequestID(requestID string) StructuredLogger
- func (l *ProfileLogger) WithSpanID(spanID string) StructuredLogger
- func (l *ProfileLogger) WithTenantID(tenantID string) StructuredLogger
- func (l *ProfileLogger) WithTraceID(traceID string) StructuredLogger
- func (l *ProfileLogger) WithUserID(userID string) StructuredLogger
- type ProfileLoggerOption
- type SanitizerFunc
- type StructuredLogger
- type TestLogger
- func (l *TestLogger) Close() error
- func (l *TestLogger) Debug(message string, fields ...map[string]any)
- func (l *TestLogger) Entries() []LogEntry
- func (l *TestLogger) Error(message string, fields ...map[string]any)
- func (l *TestLogger) Flush(ctx context.Context) error
- func (l *TestLogger) GetStats() LoggerStats
- func (l *TestLogger) Info(message string, fields ...map[string]any)
- func (l *TestLogger) IsHealthy() bool
- func (l *TestLogger) Warn(message string, fields ...map[string]any)
- func (l *TestLogger) WithField(key string, value any) StructuredLogger
- func (l *TestLogger) WithFields(fields map[string]any) StructuredLogger
- func (l *TestLogger) WithRequestID(requestID string) StructuredLogger
- func (l *TestLogger) WithSpanID(spanID string) StructuredLogger
- func (l *TestLogger) WithTenantID(tenantID string) StructuredLogger
- func (l *TestLogger) WithTraceID(traceID string) StructuredLogger
- func (l *TestLogger) WithUserID(userID string) StructuredLogger
Constants ¶
const ( LoggingProfilePayTheoryAlertV1 = "paytheory-alert-v1" LoggingProfileCloudWatchJSON = "cloudwatch-json" LoggingProfileLegacy = "legacy" LoggingProfileLocalDev = "local-dev" )
const LoggingProfileSchemaVersion = "apptheory.logging/v1"
Variables ¶
This section is empty.
Functions ¶
func BuiltInLoggingProfileNames ¶
func BuiltInLoggingProfileNames() []string
func EncodeLoggingProfileEvent ¶
func EncodeLoggingProfileEvent(config LoggingProfileConfig, environment map[string]string, event LoggingProfileEvent) (map[string]any, error)
func EncodeLoggingProfileEventWithSanitizer ¶
func EncodeLoggingProfileEventWithSanitizer(config LoggingProfileConfig, environment map[string]string, event LoggingProfileEvent, sanitizerFn SanitizerFunc) (map[string]any, error)
func HooksFromEMFMetricSink ¶
func HooksFromEMFMetricSink(sink *EMFMetricSink) apptheory.ObservabilityHooks
HooksFromEMFMetricSink bridges AppTheory metric hooks to the first-party EMF sink.
func HooksFromLogger ¶
func HooksFromLogger(logger StructuredLogger) apptheory.ObservabilityHooks
func HooksFromLoggerAndEMFMetricSink ¶
func HooksFromLoggerAndEMFMetricSink(logger StructuredLogger, sink *EMFMetricSink) apptheory.ObservabilityHooks
HooksFromLoggerAndEMFMetricSink bridges AppTheory logs to a StructuredLogger and metrics to EMF.
func LoggingProfileCatalog ¶
func LoggingProfileValidationErrors ¶
func LoggingProfileValidationErrors(config LoggingProfileConfig) []string
func ValidateLoggingProfile ¶
func ValidateLoggingProfile(config LoggingProfileConfig) error
Types ¶
type EMFMetricSink ¶
type EMFMetricSink struct {
// contains filtered or unexported fields
}
EMFMetricSink writes AppTheory request metrics in the blessed CloudWatch EMF JSON-line format.
func NewEMFMetricSink ¶
func NewEMFMetricSink(options ...EMFMetricSinkOption) *EMFMetricSink
NewEMFMetricSink creates a first-party CloudWatch Embedded Metric Format sink.
func (*EMFMetricSink) EncodeMetric ¶
func (sink *EMFMetricSink) EncodeMetric(record apptheory.MetricRecord) ([]byte, error)
EncodeMetric returns the exact JSON log line for an AppTheory request metric.
The CloudWatch dimension tuple is bounded to service, method, route template, status class, and error code. The concrete request path, raw status code, and any client-supplied tenant hint are deliberately excluded: they are attacker-influenced and would let unauthenticated requests mint unbounded custom metric series (and billing) for every unique value. Those concrete values remain available on the framework's request log and span records, which carry no metric-cardinality cost; an authenticated, bounded tenant identity could be added as a dimension later, but no such binding is invented here.
func (*EMFMetricSink) RecordMetric ¶
func (sink *EMFMetricSink) RecordMetric(record apptheory.MetricRecord)
RecordMetric records one AppTheory request metric as one EMF JSON log line.
type EMFMetricSinkOption ¶
type EMFMetricSinkOption func(*EMFMetricSink)
func WithEMFClock ¶
func WithEMFClock(clock func() time.Time) EMFMetricSinkOption
WithEMFClock sets the clock used for the required EMF Timestamp.
func WithEMFNamespace ¶
func WithEMFNamespace(namespace string) EMFMetricSinkOption
WithEMFNamespace sets the CloudWatch metric namespace. Empty values restore the AppTheory default.
func WithEMFService ¶
func WithEMFService(service string) EMFMetricSinkOption
WithEMFService sets the service dimension value. Empty values restore the AppTheory default.
func WithEMFWriter ¶
func WithEMFWriter(writer io.Writer) EMFMetricSinkOption
WithEMFWriter sets the JSON-line writer. Nil discards output.
type ErrorNotifier ¶
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.
This type is intentionally small and stable so implementations can adapt it to their backend.
type LoggerConfig ¶
type LoggerConfig struct {
Format string `json:"format"`
Level string `json:"level"`
RetryDelay time.Duration `json:"retry_delay"`
BatchSize int `json:"batch_size"`
// BufferSize is accepted for compatibility and has no effect on the zap
// logger: error notifications are delivered synchronously inside the call
// that logs, so there is no notification queue to size.
BufferSize int `json:"buffer_size"`
MaxRetries int `json:"max_retries"`
EnableStack bool `json:"enable_stack"`
EnableCaller bool `json:"enable_caller"`
SanitizationPolicy *sanitization.Policy `json:"sanitization,omitempty"`
}
LoggerConfig configures logger implementations.
Fields are intentionally aligned with Lift’s `observability.LoggerConfig` where it matters for migrations.
type LoggerFactory ¶
type LoggerFactory interface {
CreateConsoleLogger(config LoggerConfig) (StructuredLogger, error)
CreateTestLogger() StructuredLogger
CreateNoOpLogger() StructuredLogger
}
type LoggerStats ¶
type LoggerStats struct {
LastFlush time.Time `json:"last_flush"`
LastError string `json:"last_error,omitempty"`
EntriesLogged int64 `json:"entries_logged"`
EntriesDropped int64 `json:"entries_dropped"`
FlushCount int64 `json:"flush_count"`
ErrorCount int64 `json:"error_count"`
AverageFlush time.Duration `json:"average_flush_time"`
}
type LoggingProfileConfig ¶
type LoggingProfileConfig struct {
SchemaVersion string `json:"schema_version" yaml:"schema_version"`
Profile string `json:"profile" yaml:"profile"`
Encoding LoggingProfileEncoding `json:"encoding" yaml:"encoding"`
Levels map[string]string `json:"levels,omitempty" yaml:"levels,omitempty"`
RequiredFields []string `json:"required_fields,omitempty" yaml:"required_fields,omitempty"`
RecommendedFields []string `json:"recommended_fields,omitempty" yaml:"recommended_fields,omitempty"`
FieldMap map[string]string `json:"field_map,omitempty" yaml:"field_map,omitempty"`
Enrichment LoggingProfileEnrichment `json:"enrichment,omitempty" yaml:"enrichment,omitempty"`
ErrorCapture LoggingProfileErrorCapture `json:"error_capture,omitempty" yaml:"error_capture,omitempty"`
Sanitization LoggingProfileSanitization `json:"sanitization,omitempty" yaml:"sanitization,omitempty"`
AlertingHints LoggingProfileAlertingHints `json:"alerting_hints,omitempty" yaml:"alerting_hints,omitempty"`
}
func DecodeLoggingProfileJSON ¶
func DecodeLoggingProfileJSON(raw []byte) (LoggingProfileConfig, error)
func DecodeLoggingProfileYAML ¶
func DecodeLoggingProfileYAML(raw []byte) (LoggingProfileConfig, error)
func DefaultLoggingProfile ¶
func DefaultLoggingProfile(profile string) (LoggingProfileConfig, error)
type LoggingProfileEncoding ¶
type LoggingProfileEncoding struct {
Format string `json:"format" yaml:"format"`
TimestampField string `json:"timestamp_field,omitempty" yaml:"timestamp_field,omitempty"`
TimestampFormat string `json:"timestamp_format,omitempty" yaml:"timestamp_format,omitempty"`
LevelField string `json:"level_field,omitempty" yaml:"level_field,omitempty"`
MessageField string `json:"message_field,omitempty" yaml:"message_field,omitempty"`
}
type LoggingProfileError ¶
type LoggingProfileErrorCapture ¶
type LoggingProfileErrorCapture struct {
IncludeErrorType bool `json:"include_error_type" yaml:"include_error_type"`
IncludeErrorCode bool `json:"include_error_code" yaml:"include_error_code"`
IncludeStackTrace bool `json:"include_stack_trace" yaml:"include_stack_trace"`
StackTraceField string `json:"stack_trace_field,omitempty" yaml:"stack_trace_field,omitempty"`
StackHashField string `json:"stack_hash_field,omitempty" yaml:"stack_hash_field,omitempty"`
StackHashAlgorithm string `json:"stack_hash_algorithm,omitempty" yaml:"stack_hash_algorithm,omitempty"`
}
type LoggingProfileEvent ¶
type LoggingProfileEvent struct {
Timestamp time.Time `json:"timestamp"`
Level string `json:"level"`
Event string `json:"event,omitempty"`
Message string `json:"message"`
NormalizedMessage string `json:"normalized_message,omitempty"`
Request LoggingProfileRequestContext `json:"request,omitempty"`
Job LoggingProfileJobContext `json:"job,omitempty"`
Error LoggingProfileError `json:"error,omitempty"`
Fields map[string]any `json:"fields,omitempty"`
}
type LoggingProfileJobContext ¶
type LoggingProfileJobContext struct {
Name string `json:"name,omitempty"`
}
type LoggingProfileRequestContext ¶
type LoggingProfileRequestContext struct {
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"`
CorrelationID string `json:"correlation_id,omitempty"`
Route string `json:"route,omitempty"`
Method string `json:"method,omitempty"`
Path string `json:"path,omitempty"`
Status int `json:"status,omitempty"`
}
type LoggingProfileValidationError ¶
type LoggingProfileValidationError struct {
Errors []string
}
func (*LoggingProfileValidationError) Error ¶
func (e *LoggingProfileValidationError) Error() string
type ProfileLogger ¶
type ProfileLogger struct {
// contains filtered or unexported fields
}
func HooksFromProfileLogger ¶
func HooksFromProfileLogger(config LoggingProfileConfig, options ...ProfileLoggerOption) (apptheory.ObservabilityHooks, *ProfileLogger, error)
func NewProfileLogger ¶
func NewProfileLogger(config LoggingProfileConfig, options ...ProfileLoggerOption) (*ProfileLogger, error)
func (*ProfileLogger) Close ¶
func (l *ProfileLogger) Close() error
func (*ProfileLogger) Debug ¶
func (l *ProfileLogger) Debug(message string, fields ...map[string]any)
func (*ProfileLogger) Entries ¶
func (l *ProfileLogger) Entries() []map[string]any
func (*ProfileLogger) Error ¶
func (l *ProfileLogger) Error(message string, fields ...map[string]any)
func (*ProfileLogger) GetStats ¶
func (l *ProfileLogger) GetStats() LoggerStats
func (*ProfileLogger) IsHealthy ¶
func (l *ProfileLogger) IsHealthy() bool
func (*ProfileLogger) WithField ¶
func (l *ProfileLogger) WithField(key string, value any) StructuredLogger
func (*ProfileLogger) WithFields ¶
func (l *ProfileLogger) WithFields(fields map[string]any) StructuredLogger
func (*ProfileLogger) WithRequestID ¶
func (l *ProfileLogger) WithRequestID(requestID string) StructuredLogger
func (*ProfileLogger) WithSpanID ¶
func (l *ProfileLogger) WithSpanID(spanID string) StructuredLogger
func (*ProfileLogger) WithTenantID ¶
func (l *ProfileLogger) WithTenantID(tenantID string) StructuredLogger
func (*ProfileLogger) WithTraceID ¶
func (l *ProfileLogger) WithTraceID(traceID string) StructuredLogger
func (*ProfileLogger) WithUserID ¶
func (l *ProfileLogger) WithUserID(userID string) StructuredLogger
type ProfileLoggerOption ¶
type ProfileLoggerOption func(*profileLoggerOptions)
func WithProfileClock ¶
func WithProfileClock(clock func() time.Time) ProfileLoggerOption
func WithProfileEnvironment ¶
func WithProfileEnvironment(environment map[string]string) ProfileLoggerOption
func WithProfileSanitizer ¶
func WithProfileSanitizer(fn SanitizerFunc) ProfileLoggerOption
func WithProfileWriter ¶
func WithProfileWriter(writer io.Writer) ProfileLoggerOption
type SanitizerFunc ¶
type StructuredLogger ¶
type StructuredLogger interface {
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) StructuredLogger
WithFields(fields map[string]any) StructuredLogger
WithRequestID(requestID string) StructuredLogger
WithTenantID(tenantID string) StructuredLogger
WithUserID(userID string) StructuredLogger
WithTraceID(traceID string) StructuredLogger
WithSpanID(spanID string) StructuredLogger
Flush(ctx context.Context) error
Close() error
IsHealthy() bool
GetStats() LoggerStats
}
StructuredLogger is the primary Go logging surface used by Pay Theory migrations.
It intentionally mirrors the Lift logger API shape (message + map fields) while allowing implementations to provide stronger guarantees (sanitization, health, lifecycle).
func NewNoOpLogger ¶
func NewNoOpLogger() StructuredLogger
type TestLogger ¶
type TestLogger struct {
// contains filtered or unexported fields
}
TestLogger is an in-memory logger implementation for deterministic unit tests.
Derived loggers (via With* calls) share the same underlying core.
func NewTestLogger ¶
func NewTestLogger() *TestLogger
func (*TestLogger) Close ¶
func (l *TestLogger) Close() error
func (*TestLogger) Entries ¶
func (l *TestLogger) Entries() []LogEntry
func (*TestLogger) GetStats ¶
func (l *TestLogger) GetStats() LoggerStats
func (*TestLogger) IsHealthy ¶
func (l *TestLogger) IsHealthy() bool
func (*TestLogger) WithField ¶
func (l *TestLogger) WithField(key string, value any) StructuredLogger
func (*TestLogger) WithFields ¶
func (l *TestLogger) WithFields(fields map[string]any) StructuredLogger
func (*TestLogger) WithRequestID ¶
func (l *TestLogger) WithRequestID(requestID string) StructuredLogger
func (*TestLogger) WithSpanID ¶
func (l *TestLogger) WithSpanID(spanID string) StructuredLogger
func (*TestLogger) WithTenantID ¶
func (l *TestLogger) WithTenantID(tenantID string) StructuredLogger
func (*TestLogger) WithTraceID ¶
func (l *TestLogger) WithTraceID(traceID string) StructuredLogger
func (*TestLogger) WithUserID ¶
func (l *TestLogger) WithUserID(userID string) StructuredLogger