Documentation
¶
Index ¶
- type BackendPlugin
- type Config
- type DefaultEventTransformer
- type EventPayload
- type EventTransformer
- type HealthStatus
- type PermanentBackendError
- type Service
- func (s *Service) DetailedStats() map[string]interface{}
- func (s *Service) EventBus() eventbus.EventBus
- func (s *Service) Health(ctx context.Context) HealthStatus
- func (s *Service) Run(ctx context.Context, detach bool) error
- func (s *Service) Stats() (processed, dropped, sent int64)
- func (s *Service) Stop() error
- type TokensUsage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackendPlugin ¶
type BackendPlugin interface {
// Init initializes the plugin with configuration
Init(cfg map[string]string) error
// SendEvents sends a batch of events to the backend
SendEvents(ctx context.Context, events []EventPayload) error
// Close cleans up any resources used by the plugin
Close() error
}
BackendPlugin defines the interface for dispatcher backends
type Config ¶
type Config struct {
BufferSize int
BatchSize int
FlushInterval time.Duration
RetryAttempts int
RetryBackoff time.Duration
Plugin BackendPlugin
EventTransformer EventTransformer
PluginName string
Verbose bool // If true, include response_headers and extra debug info
}
Config holds configuration for the dispatcher service
type DefaultEventTransformer ¶
type DefaultEventTransformer struct {
Verbose bool
}
DefaultEventTransformer provides a basic transformation from eventbus.Event to EventPayload Verbose: if true, includes response_headers in metadata Use NewDefaultEventTransformer(verbose) to construct
func NewDefaultEventTransformer ¶
func NewDefaultEventTransformer(verbose bool) *DefaultEventTransformer
NewDefaultEventTransformer creates a transformer with the given verbosity
func (*DefaultEventTransformer) Transform ¶
func (t *DefaultEventTransformer) Transform(evt eventbus.Event) (*EventPayload, error)
Transform converts an eventbus.Event to an EventPayload
type EventPayload ¶
type EventPayload struct {
Type string `json:"type"`
Event string `json:"event"`
RunID string `json:"runId"`
ParentRunID *string `json:"parentRunId,omitempty"`
Name *string `json:"name,omitempty"`
Timestamp time.Time `json:"timestamp"`
Input json.RawMessage `json:"input,omitempty"`
InputBase64 string `json:"input_base64,omitempty"` // base64 if not valid JSON
Output json.RawMessage `json:"output,omitempty"`
OutputBase64 string `json:"output_base64,omitempty"` // base64 if not valid JSON
// Additional fields for enhanced observability
UserID *string `json:"userId,omitempty"`
TokensUsage *TokensUsage `json:"tokensUsage,omitempty"`
UserProps map[string]any `json:"userProps,omitempty"`
Extra map[string]any `json:"extra,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"`
LogID int64 `json:"log_id"` // Unique, monotonic event log ID
}
EventPayload represents the extended event format for external services
type EventTransformer ¶
type EventTransformer interface {
Transform(evt eventbus.Event) (*EventPayload, error)
}
EventTransformer transforms eventbus.Event to EventPayload
type HealthStatus ¶
type HealthStatus struct {
// Healthy indicates whether the dispatcher is currently healthy.
Healthy bool `json:"healthy"`
// Status is a human-readable string describing the current health status.
Status string `json:"status"`
// EventsProcessed is the total number of events processed by the dispatcher.
EventsProcessed int64 `json:"events_processed"`
// EventsDropped is the total number of events that were dropped and not processed.
EventsDropped int64 `json:"events_dropped"`
// EventsSent is the total number of events successfully sent to the backend.
EventsSent int64 `json:"events_sent"`
// ProcessingRate is the average number of events processed per second.
ProcessingRate float64 `json:"processing_rate"`
// LagCount is the number of pending messages in the event bus that have not yet been processed.
// For Redis Streams, this is the pending entries count (XPENDING).
LagCount int64 `json:"lag_count"`
// StreamLength is the total number of messages currently in the Redis Stream.
// For Redis Streams, this is the stream length (XLEN).
StreamLength int64 `json:"stream_length"`
// LastProcessedAt is the timestamp of the last successfully processed event.
LastProcessedAt time.Time `json:"last_processed_at"`
// Message provides additional information about the health status, if any.
Message string `json:"message,omitempty"`
}
HealthStatus represents the health status of the dispatcher.
type PermanentBackendError ¶
type PermanentBackendError struct {
Msg string
}
PermanentBackendError is a custom error type for permanent backend errors (e.g., Helicone 500s that should not be retried)
func (*PermanentBackendError) Error ¶
func (e *PermanentBackendError) Error() string
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents the event dispatcher service
func NewService ¶
NewService creates a new dispatcher service
func NewServiceWithBus ¶
NewServiceWithBus creates a new dispatcher service with a provided event bus.
func (*Service) DetailedStats ¶
DetailedStats returns detailed service statistics including lag and rate
func (*Service) EventBus ¶
EventBus returns the event bus for this service (for connecting with other components)
func (*Service) Health ¶
func (s *Service) Health(ctx context.Context) HealthStatus
Health returns the health status of the dispatcher
type TokensUsage ¶
TokensUsage represents token usage statistics