yao/trace/types/driver.go
Max b582f0c685 Refactor trace package structure and improve trace ID validation
- Updated trace ID validation in `TestEnterStack_RootCreation` to ensure it is at least 8 digits long.
- Changed import path for the trace package in `stack.go` for consistency.
- Removed the entire `manager.go`, `node.go`, `space.go`, `subscription.go`, `trace.go`, `local/driver.go`, `store/driver.go`, and related types and events files to streamline the trace package, focusing on essential functionality.
2025-11-18 14:09:28 +08:00

73 lines
2.7 KiB
Go

package types
import "context"
// TraceLog represents a log entry
type TraceLog struct {
Timestamp int64 // Log timestamp
Level string // Log level (info, debug, error, warn)
Message string // Log message
NodeID string // Node ID this log belongs to
}
// Driver defines the storage driver interface that providers must implement
// Driver is only responsible for persistence operations, not business logic
type Driver interface {
// SaveNode persists a node to storage
SaveNode(ctx context.Context, traceID string, node *TraceNode) error
// LoadNode loads a node from storage
LoadNode(ctx context.Context, traceID string, nodeID string) (*TraceNode, error)
// LoadTrace loads the entire trace tree from storage
LoadTrace(ctx context.Context, traceID string) (*TraceNode, error)
// SaveSpace persists a space to storage
SaveSpace(ctx context.Context, traceID string, space *TraceSpace) error
// LoadSpace loads a space from storage
LoadSpace(ctx context.Context, traceID string, spaceID string) (*TraceSpace, error)
// DeleteSpace removes a space from storage
DeleteSpace(ctx context.Context, traceID string, spaceID string) error
// ListSpaces lists all space IDs for a trace
ListSpaces(ctx context.Context, traceID string) ([]string, error)
// Space KV Operations
// SetSpaceKey stores a value by key in a space
SetSpaceKey(ctx context.Context, traceID, spaceID, key string, value any) error
// GetSpaceKey retrieves a value by key from a space
GetSpaceKey(ctx context.Context, traceID, spaceID, key string) (any, error)
// HasSpaceKey checks if a key exists in a space
HasSpaceKey(ctx context.Context, traceID, spaceID, key string) bool
// DeleteSpaceKey removes a key-value pair from a space
DeleteSpaceKey(ctx context.Context, traceID, spaceID, key string) error
// ClearSpaceKeys removes all key-value pairs from a space
ClearSpaceKeys(ctx context.Context, traceID, spaceID string) error
// ListSpaceKeys returns all keys in a space
ListSpaceKeys(ctx context.Context, traceID, spaceID string) ([]string, error)
// SaveLog appends a log entry to storage
SaveLog(ctx context.Context, traceID string, log *TraceLog) error
// LoadLogs loads all logs for a trace or specific node
LoadLogs(ctx context.Context, traceID string, nodeID string) ([]*TraceLog, error)
// SaveTraceInfo persists trace metadata to storage
SaveTraceInfo(ctx context.Context, info *TraceInfo) error
// LoadTraceInfo loads trace metadata from storage
LoadTraceInfo(ctx context.Context, traceID string) (*TraceInfo, error)
// DeleteTrace removes entire trace and all its data
DeleteTrace(ctx context.Context, traceID string) error
// Close closes the driver and releases resources
Close() error
}