{"modulePath":"github.com/GoCodeAlone/workflow","version":"v0.87.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package observability\n\n## Types\n\n```go\ntype EventReport struct {\n\tExecutionID string         `json:\"execution_id\"`\n\tEventType   string         `json:\"event_type\"`\n\tEventData   map[string]any `json:\"event_data\"`\n\tCreatedAt   string         `json:\"created_at\"`\n}\n```\nEventReport represents an event to report to the admin.\n\n```go\ntype ExecutionReport struct {\n\tID           string    `json:\"id\"`\n\tWorkflowID   string    `json:\"workflow_id\"`\n\tTriggerType  string    `json:\"trigger_type\"`\n\tStatus       string    `json:\"status\"`\n\tTriggeredBy  string    `json:\"triggered_by,omitempty\"`\n\tErrorMessage string    `json:\"error_message,omitempty\"`\n\tStartedAt    time.Time `json:\"started_at\"`\n\tCompletedAt  time.Time `json:\"completed_at,omitempty\"`\n\tDurationMs   int64     `json:\"duration_ms\"`\n}\n```\nExecutionReport represents an execution record to report to the admin.\n\n```go\ntype ExecutionTracker struct {\n\t// contains filtered or unexported fields\n}\n```\nExecutionTracker wraps execution lifecycle to record executions, steps, and logs.\n\n```go\nfunc NewExecutionTracker(executions store.ExecutionStore, logs store.LogStore) *ExecutionTracker\n```\nNewExecutionTracker creates a new ExecutionTracker.\n\n```go\nfunc (t *ExecutionTracker) CancelExecution(ctx context.Context, executionID uuid.UUID) error\n```\nCancelExecution marks an execution as cancelled.\n\n```go\nfunc (t *ExecutionTracker) CompleteExecution(ctx context.Context, executionID uuid.UUID, output json.RawMessage) error\n```\nCompleteExecution marks an execution as successfully completed.\n\n```go\nfunc (t *ExecutionTracker) FailExecution(ctx context.Context, executionID uuid.UUID, execErr error) error\n```\nFailExecution marks an execution as failed.\n\n```go\nfunc (t *ExecutionTracker) LogWriter(workflowID uuid.UUID, executionID uuid.UUID, level store.LogLevel) io.Writer\n```\nLogWriter returns an io.Writer that appends logs to the store at the given level.\n\n```go\nfunc (t *ExecutionTracker) RecordStep(ctx context.Context, executionID uuid.UUID, step *store.ExecutionStep) error\n```\nRecordStep records a step within an execution.\n\n```go\nfunc (t *ExecutionTracker) StartExecution(ctx context.Context, workflowID uuid.UUID, triggerType string, data json.RawMessage) (uuid.UUID, error)\n```\nStartExecution begins tracking a new workflow execution.\n\n```go\ntype IngestHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nIngestHandler handles incoming observability data from worker instances. It is registered on the admin server to receive batches from reporters.\n\n```go\nfunc NewIngestHandler(store IngestStore, logger *slog.Logger) *IngestHandler\n```\nNewIngestHandler creates a new handler for admin ingest endpoints.\n\n```go\nfunc (h *IngestHandler) RegisterRoutes(mux *http.ServeMux)\n```\nRegisterRoutes registers the ingest API routes on the given mux.\n\n```go\ntype IngestStore interface {\n\tIngestExecutions(ctx context.Context, instance string, items []ExecutionReport) error\n\tIngestLogs(ctx context.Context, instance string, items []LogReport) error\n\tIngestEvents(ctx context.Context, instance string, items []EventReport) error\n\tRegisterInstance(ctx context.Context, name string, registeredAt time.Time) error\n\tHeartbeat(ctx context.Context, name string, timestamp time.Time) error\n}\n```\nIngestStore defines the storage interface for ingested observability data.\n\n```go\ntype LogReport struct {\n\tWorkflowID  string `json:\"workflow_id\"`\n\tExecutionID string `json:\"execution_id,omitempty\"`\n\tLevel       string `json:\"level\"`\n\tMessage     string `json:\"message\"`\n\tModuleName  string `json:\"module_name,omitempty\"`\n\tFields      string `json:\"fields,omitempty\"`\n\tCreatedAt   string `json:\"created_at\"`\n}\n```\nLogReport represents a log entry to report to the admin.\n\n```go\ntype Reporter struct {\n\t// contains filtered or unexported fields\n}\n```\nReporter buffers observability data and periodically flushes it to the admin server.\n\n```go\nfunc NewReporter(config ReporterConfig, logger *slog.Logger) *Reporter\n```\nNewReporter creates a new observability reporter.\n\n```go\nfunc ReporterFromEnv(logger *slog.Logger) *Reporter\n```\nReporterFromEnv creates a Reporter from environment variables. Returns nil if WORKFLOW\\_ADMIN\\_URL is not set.\n\n```go\nfunc (r *Reporter) ReportEvent(event EventReport)\n```\nReportEvent buffers an event for the next flush.\n\n```go\nfunc (r *Reporter) ReportExecution(exec ExecutionReport)\n```\nReportExecution buffers an execution record for the next flush.\n\n```go\nfunc (r *Reporter) ReportLog(log LogReport)\n```\nReportLog buffers a log entry for the next flush.\n\n```go\nfunc (r *Reporter) Start(ctx context.Context)\n```\nStart begins the background flush and heartbeat loops.\n\n```go\nfunc (r *Reporter) Stop()\n```\nStop shuts down the reporter, performing a final flush.\n\n```go\ntype ReporterConfig struct {\n\t// AdminURL is the base URL of the admin server (e.g., \"http://admin-server:8081\").\n\tAdminURL string `yaml:\"admin_url\" json:\"admin_url\"`\n\t// FlushInterval is how often buffered data is sent to the admin server.\n\tFlushInterval time.Duration `yaml:\"flush_interval\" json:\"flush_interval\"`\n\t// BatchSize is the maximum number of items per flush batch.\n\tBatchSize int `yaml:\"batch_size\" json:\"batch_size\"`\n\t// InstanceName identifies this worker instance.\n\tInstanceName string `yaml:\"instance_name\" json:\"instance_name\"`\n\t// HeartbeatInterval is how often to send heartbeats to the admin server.\n\tHeartbeatInterval time.Duration `yaml:\"heartbeat_interval\" json:\"heartbeat_interval\"`\n}\n```\nReporterConfig configures the built-in observability reporter.\n\n```go\nfunc DefaultReporterConfig() ReporterConfig\n```\nDefaultReporterConfig returns a config with sensible defaults.\n\n```go\ntype V1IngestStore struct {\n\t// contains filtered or unexported fields\n}\n```\nV1IngestStore implements IngestStore by writing to the V1Store's SQLite database. It inserts ingested data directly into the execution\\_logs, workflow\\_executions, and execution\\_events tables.\n\n```go\nfunc NewV1IngestStore(db *sql.DB) *V1IngestStore\n```\nNewV1IngestStore creates a new ingest store backed by the given database.\n\n```go\nfunc (s *V1IngestStore) Heartbeat(_ context.Context, name string, timestamp time.Time) error\n```\nHeartbeat updates the last\\_seen timestamp for a worker instance.\n\n```go\nfunc (s *V1IngestStore) IngestEvents(_ context.Context, _ string, items []EventReport) error\n```\nIngestEvents writes events from a remote worker to the execution\\_events table.\n\n```go\nfunc (s *V1IngestStore) IngestExecutions(_ context.Context, instance string, items []ExecutionReport) error\n```\nIngestExecutions writes execution records from a remote worker.\n\n```go\nfunc (s *V1IngestStore) IngestLogs(_ context.Context, _ string, items []LogReport) error\n```\nIngestLogs writes log entries from a remote worker.\n\n```go\nfunc (s *V1IngestStore) ListInstances() ([]WorkerInstance, error)\n```\nListInstances returns all registered worker instances.\n\n```go\nfunc (s *V1IngestStore) RegisterInstance(_ context.Context, name string, registeredAt time.Time) error\n```\nRegisterInstance records a new worker instance.\n\n```go\ntype WorkerInstance struct {\n\tName         string `json:\"name\"`\n\tStatus       string `json:\"status\"`\n\tLastSeen     string `json:\"last_seen\"`\n\tRegisteredAt string `json:\"registered_at\"`\n}\n```\nWorkerInstance represents a registered remote worker.\n\n","path":"github.com/GoCodeAlone/workflow/observability","name":"observability","synopsis":"","isRedistributable":true}
