Documentation
¶
Index ¶
- type CartCheckoutEvent
- type CartCreatedEvent
- type CartHook
- type DatabaseHook
- type DatabaseQueryEvent
- type Hook
- type PaymentCompletedEvent
- type PaymentHook
- type PaymentSettledEvent
- type PaymentStartedEvent
- type PrometheusHook
- func (h *PrometheusHook) Name() string
- func (h *PrometheusHook) OnCartCheckout(ctx context.Context, event CartCheckoutEvent)
- func (h *PrometheusHook) OnCartCreated(ctx context.Context, event CartCreatedEvent)
- func (h *PrometheusHook) OnDatabaseQuery(ctx context.Context, event DatabaseQueryEvent)
- func (h *PrometheusHook) OnPaymentCompleted(ctx context.Context, event PaymentCompletedEvent)
- func (h *PrometheusHook) OnPaymentSettled(ctx context.Context, event PaymentSettledEvent)
- func (h *PrometheusHook) OnPaymentStarted(ctx context.Context, event PaymentStartedEvent)
- func (h *PrometheusHook) OnRPCCall(ctx context.Context, event RPCCallEvent)
- func (h *PrometheusHook) OnRefundProcessed(ctx context.Context, event RefundProcessedEvent)
- func (h *PrometheusHook) OnRefundRequested(ctx context.Context, event RefundRequestedEvent)
- func (h *PrometheusHook) OnWebhookDelivered(ctx context.Context, event WebhookDeliveredEvent)
- func (h *PrometheusHook) OnWebhookFailed(ctx context.Context, event WebhookFailedEvent)
- func (h *PrometheusHook) OnWebhookQueued(ctx context.Context, event WebhookQueuedEvent)
- func (h *PrometheusHook) OnWebhookRetried(ctx context.Context, event WebhookRetriedEvent)
- type RPCCallEvent
- type RPCHook
- type RefundHook
- type RefundProcessedEvent
- type RefundRequestedEvent
- type Registry
- func (r *Registry) EmitCartCheckout(ctx context.Context, event CartCheckoutEvent)
- func (r *Registry) EmitCartCreated(ctx context.Context, event CartCreatedEvent)
- func (r *Registry) EmitDatabaseQuery(ctx context.Context, event DatabaseQueryEvent)
- func (r *Registry) EmitPaymentCompleted(ctx context.Context, event PaymentCompletedEvent)
- func (r *Registry) EmitPaymentSettled(ctx context.Context, event PaymentSettledEvent)
- func (r *Registry) EmitPaymentStarted(ctx context.Context, event PaymentStartedEvent)
- func (r *Registry) EmitRPCCall(ctx context.Context, event RPCCallEvent)
- func (r *Registry) EmitRefundProcessed(ctx context.Context, event RefundProcessedEvent)
- func (r *Registry) EmitRefundRequested(ctx context.Context, event RefundRequestedEvent)
- func (r *Registry) EmitWebhookDelivered(ctx context.Context, event WebhookDeliveredEvent)
- func (r *Registry) EmitWebhookFailed(ctx context.Context, event WebhookFailedEvent)
- func (r *Registry) EmitWebhookQueued(ctx context.Context, event WebhookQueuedEvent)
- func (r *Registry) EmitWebhookRetried(ctx context.Context, event WebhookRetriedEvent)
- func (r *Registry) RegisterCartHook(hook CartHook)
- func (r *Registry) RegisterDatabaseHook(hook DatabaseHook)
- func (r *Registry) RegisterPaymentHook(hook PaymentHook)
- func (r *Registry) RegisterRPCHook(hook RPCHook)
- func (r *Registry) RegisterRefundHook(hook RefundHook)
- func (r *Registry) RegisterWebhookHook(hook WebhookHook)
- type WebhookDeliveredEvent
- type WebhookFailedEvent
- type WebhookHook
- type WebhookQueuedEvent
- type WebhookRetriedEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CartCheckoutEvent ¶
type CartCheckoutEvent struct {
Timestamp time.Time
CartID string
ItemCount int
TotalAmount int64
Token string
Status string // "success", "failed", "pending"
PaymentMethod string
Wallet string
Metadata map[string]string
}
CartCheckoutEvent is emitted when a cart checkout is attempted.
type CartCreatedEvent ¶
type CartCreatedEvent struct {
Timestamp time.Time
CartID string
ItemCount int
TotalAmount int64
Token string
ExpiresAt time.Time
Metadata map[string]string
}
CartCreatedEvent is emitted when a cart quote is created.
type CartHook ¶
type CartHook interface {
Hook
// OnCartCreated is called when a cart quote is created.
OnCartCreated(ctx context.Context, event CartCreatedEvent)
// OnCartCheckout is called when a cart checkout is attempted.
OnCartCheckout(ctx context.Context, event CartCheckoutEvent)
}
CartHook receives events during cart operations.
type DatabaseHook ¶
type DatabaseHook interface {
Hook
// OnDatabaseQuery is called for database queries.
OnDatabaseQuery(ctx context.Context, event DatabaseQueryEvent)
}
DatabaseHook receives events from database operations.
type DatabaseQueryEvent ¶
type DatabaseQueryEvent struct {
Timestamp time.Time
Operation string // "get", "list", "save", "delete", etc.
Backend string // "postgres", "mongodb", "file", "memory"
Duration time.Duration
Success bool
Error string
Metadata map[string]string
}
DatabaseQueryEvent is emitted for database operations.
type Hook ¶
type Hook interface {
// Name returns the hook's identifier for logging/debugging
Name() string
}
Hook is the base interface for all observability hooks. Implementations can emit events to DataDog, New Relic, OpenTelemetry, etc.
type PaymentCompletedEvent ¶
type PaymentCompletedEvent struct {
Timestamp time.Time
PaymentID string
Method string
ResourceID string
Success bool
ErrorReason string // Set if Success=false
Amount int64
Token string
Wallet string
Duration time.Duration // Time from start to completion
TransactionID string // Blockchain tx signature or Stripe session ID
Metadata map[string]string
}
PaymentCompletedEvent is emitted when a payment completes.
type PaymentHook ¶
type PaymentHook interface {
Hook
// OnPaymentStarted is called when a payment request is received.
OnPaymentStarted(ctx context.Context, event PaymentStartedEvent)
// OnPaymentCompleted is called when a payment succeeds or fails.
OnPaymentCompleted(ctx context.Context, event PaymentCompletedEvent)
// OnPaymentSettled is called when payment is confirmed on-chain.
OnPaymentSettled(ctx context.Context, event PaymentSettledEvent)
}
PaymentHook receives events during the payment lifecycle.
type PaymentSettledEvent ¶
type PaymentSettledEvent struct {
Timestamp time.Time
PaymentID string
Network string // "solana-mainnet", "ethereum-mainnet", etc.
TransactionID string
Confirmations int
SettlementDuration time.Duration // Time from payment to settlement
}
PaymentSettledEvent is emitted when on-chain settlement is confirmed.
type PaymentStartedEvent ¶
type PaymentStartedEvent struct {
Timestamp time.Time
PaymentID string
Method string // "stripe" or "x402"
ResourceID string
Amount int64 // Amount in atomic units (e.g., cents, lamports)
Token string // Currency/token (e.g., "USD", "USDC")
Wallet string // Payer wallet address (for x402)
Metadata map[string]string
}
PaymentStartedEvent is emitted when a payment request is received.
type PrometheusHook ¶
type PrometheusHook struct {
// contains filtered or unexported fields
}
PrometheusHook adapts the existing Prometheus metrics to the hook interface. This maintains backward compatibility while allowing new hooks to be added.
func NewPrometheusHook ¶
func NewPrometheusHook(m *metrics.Metrics) *PrometheusHook
NewPrometheusHook creates a hook that emits events to Prometheus metrics.
func (*PrometheusHook) Name ¶
func (h *PrometheusHook) Name() string
func (*PrometheusHook) OnCartCheckout ¶
func (h *PrometheusHook) OnCartCheckout(ctx context.Context, event CartCheckoutEvent)
func (*PrometheusHook) OnCartCreated ¶
func (h *PrometheusHook) OnCartCreated(ctx context.Context, event CartCreatedEvent)
func (*PrometheusHook) OnDatabaseQuery ¶
func (h *PrometheusHook) OnDatabaseQuery(ctx context.Context, event DatabaseQueryEvent)
func (*PrometheusHook) OnPaymentCompleted ¶
func (h *PrometheusHook) OnPaymentCompleted(ctx context.Context, event PaymentCompletedEvent)
func (*PrometheusHook) OnPaymentSettled ¶
func (h *PrometheusHook) OnPaymentSettled(ctx context.Context, event PaymentSettledEvent)
func (*PrometheusHook) OnPaymentStarted ¶
func (h *PrometheusHook) OnPaymentStarted(ctx context.Context, event PaymentStartedEvent)
func (*PrometheusHook) OnRPCCall ¶
func (h *PrometheusHook) OnRPCCall(ctx context.Context, event RPCCallEvent)
func (*PrometheusHook) OnRefundProcessed ¶
func (h *PrometheusHook) OnRefundProcessed(ctx context.Context, event RefundProcessedEvent)
func (*PrometheusHook) OnRefundRequested ¶
func (h *PrometheusHook) OnRefundRequested(ctx context.Context, event RefundRequestedEvent)
func (*PrometheusHook) OnWebhookDelivered ¶
func (h *PrometheusHook) OnWebhookDelivered(ctx context.Context, event WebhookDeliveredEvent)
func (*PrometheusHook) OnWebhookFailed ¶
func (h *PrometheusHook) OnWebhookFailed(ctx context.Context, event WebhookFailedEvent)
func (*PrometheusHook) OnWebhookQueued ¶
func (h *PrometheusHook) OnWebhookQueued(ctx context.Context, event WebhookQueuedEvent)
func (*PrometheusHook) OnWebhookRetried ¶
func (h *PrometheusHook) OnWebhookRetried(ctx context.Context, event WebhookRetriedEvent)
type RPCCallEvent ¶
type RPCCallEvent struct {
Timestamp time.Time
Method string // "getTransaction", "sendTransaction", etc.
Network string // "solana-mainnet", etc.
Duration time.Duration
Success bool
ErrorType string // "timeout", "rate_limit", "connection", "not_found", "other"
Metadata map[string]string
}
RPCCallEvent is emitted for blockchain RPC calls.
type RPCHook ¶
type RPCHook interface {
Hook
// OnRPCCall is called before/after an RPC call.
OnRPCCall(ctx context.Context, event RPCCallEvent)
}
RPCHook receives events from blockchain RPC calls.
type RefundHook ¶
type RefundHook interface {
Hook
// OnRefundRequested is called when a refund is requested.
OnRefundRequested(ctx context.Context, event RefundRequestedEvent)
// OnRefundProcessed is called when a refund is processed (success or failure).
OnRefundProcessed(ctx context.Context, event RefundProcessedEvent)
}
RefundHook receives events during the refund lifecycle.
type RefundProcessedEvent ¶
type RefundProcessedEvent struct {
Timestamp time.Time
RefundID string
OriginalPurchaseID string
Success bool
ErrorReason string
Amount int64
Token string
TransactionID string // On-chain transaction signature
Duration time.Duration
Metadata map[string]string
}
RefundProcessedEvent is emitted when a refund is processed.
type RefundRequestedEvent ¶
type RefundRequestedEvent struct {
Timestamp time.Time
RefundID string
OriginalPurchaseID string
RecipientWallet string
Amount int64
Token string
Reason string
Metadata map[string]string
}
RefundRequestedEvent is emitted when a refund is requested.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages a collection of observability hooks. It safely dispatches events to all registered hooks with error handling.
func NewRegistry ¶
NewRegistry creates a new hook registry.
func (*Registry) EmitCartCheckout ¶
func (r *Registry) EmitCartCheckout(ctx context.Context, event CartCheckoutEvent)
EmitCartCheckout dispatches the event to all cart hooks.
func (*Registry) EmitCartCreated ¶
func (r *Registry) EmitCartCreated(ctx context.Context, event CartCreatedEvent)
EmitCartCreated dispatches the event to all cart hooks.
func (*Registry) EmitDatabaseQuery ¶
func (r *Registry) EmitDatabaseQuery(ctx context.Context, event DatabaseQueryEvent)
EmitDatabaseQuery dispatches the event to all database hooks.
func (*Registry) EmitPaymentCompleted ¶
func (r *Registry) EmitPaymentCompleted(ctx context.Context, event PaymentCompletedEvent)
EmitPaymentCompleted dispatches the event to all payment hooks.
func (*Registry) EmitPaymentSettled ¶
func (r *Registry) EmitPaymentSettled(ctx context.Context, event PaymentSettledEvent)
EmitPaymentSettled dispatches the event to all payment hooks.
func (*Registry) EmitPaymentStarted ¶
func (r *Registry) EmitPaymentStarted(ctx context.Context, event PaymentStartedEvent)
EmitPaymentStarted dispatches the event to all payment hooks.
func (*Registry) EmitRPCCall ¶
func (r *Registry) EmitRPCCall(ctx context.Context, event RPCCallEvent)
EmitRPCCall dispatches the event to all RPC hooks.
func (*Registry) EmitRefundProcessed ¶
func (r *Registry) EmitRefundProcessed(ctx context.Context, event RefundProcessedEvent)
EmitRefundProcessed dispatches the event to all refund hooks.
func (*Registry) EmitRefundRequested ¶
func (r *Registry) EmitRefundRequested(ctx context.Context, event RefundRequestedEvent)
EmitRefundRequested dispatches the event to all refund hooks.
func (*Registry) EmitWebhookDelivered ¶
func (r *Registry) EmitWebhookDelivered(ctx context.Context, event WebhookDeliveredEvent)
EmitWebhookDelivered dispatches the event to all webhook hooks.
func (*Registry) EmitWebhookFailed ¶
func (r *Registry) EmitWebhookFailed(ctx context.Context, event WebhookFailedEvent)
EmitWebhookFailed dispatches the event to all webhook hooks.
func (*Registry) EmitWebhookQueued ¶
func (r *Registry) EmitWebhookQueued(ctx context.Context, event WebhookQueuedEvent)
EmitWebhookQueued dispatches the event to all webhook hooks.
func (*Registry) EmitWebhookRetried ¶
func (r *Registry) EmitWebhookRetried(ctx context.Context, event WebhookRetriedEvent)
EmitWebhookRetried dispatches the event to all webhook hooks.
func (*Registry) RegisterCartHook ¶
RegisterCartHook adds a cart hook to the registry.
func (*Registry) RegisterDatabaseHook ¶
func (r *Registry) RegisterDatabaseHook(hook DatabaseHook)
RegisterDatabaseHook adds a database hook to the registry.
func (*Registry) RegisterPaymentHook ¶
func (r *Registry) RegisterPaymentHook(hook PaymentHook)
RegisterPaymentHook adds a payment hook to the registry.
func (*Registry) RegisterRPCHook ¶
RegisterRPCHook adds an RPC hook to the registry.
func (*Registry) RegisterRefundHook ¶
func (r *Registry) RegisterRefundHook(hook RefundHook)
RegisterRefundHook adds a refund hook to the registry.
func (*Registry) RegisterWebhookHook ¶
func (r *Registry) RegisterWebhookHook(hook WebhookHook)
RegisterWebhookHook adds a webhook hook to the registry.
type WebhookDeliveredEvent ¶
type WebhookDeliveredEvent struct {
Timestamp time.Time
WebhookID string
EventType string
URL string
EventID string
Attempts int
Duration time.Duration
StatusCode int
}
WebhookDeliveredEvent is emitted when a webhook is successfully delivered.
type WebhookFailedEvent ¶
type WebhookFailedEvent struct {
Timestamp time.Time
WebhookID string
EventType string
URL string
EventID string
Attempts int
Error string
FinalFailure bool // true if all retries exhausted
}
WebhookFailedEvent is emitted when a webhook delivery fails.
type WebhookHook ¶
type WebhookHook interface {
Hook
// OnWebhookQueued is called when a webhook is added to the delivery queue.
OnWebhookQueued(ctx context.Context, event WebhookQueuedEvent)
// OnWebhookDelivered is called when a webhook is successfully delivered.
OnWebhookDelivered(ctx context.Context, event WebhookDeliveredEvent)
// OnWebhookFailed is called when a webhook delivery fails.
OnWebhookFailed(ctx context.Context, event WebhookFailedEvent)
// OnWebhookRetried is called when a webhook is retried.
OnWebhookRetried(ctx context.Context, event WebhookRetriedEvent)
}
WebhookHook receives events during webhook delivery.
type WebhookQueuedEvent ¶
type WebhookQueuedEvent struct {
Timestamp time.Time
WebhookID string
EventType string // "payment" or "refund"
URL string
EventID string // Idempotency key for the webhook event
Metadata map[string]string
}
WebhookQueuedEvent is emitted when a webhook is queued for delivery.