recorder

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncRecorder

type AsyncRecorder struct {
	// contains filtered or unexported fields
}

AsyncRecorder calls Recorder methods asynchronously and logs any errors which may occur.

func NewAsyncRecorder

func NewAsyncRecorder(logger slog.Logger, wrapped Recorder, timeout time.Duration) *AsyncRecorder

func (*AsyncRecorder) RecordInterception

func (a *AsyncRecorder) RecordInterception(ctx context.Context, req *InterceptionRecord) error

RecordInterception must NOT be called asynchronously. If an interception cannot be recorded, the whole request should fail.

func (*AsyncRecorder) RecordInterceptionEnded

func (a *AsyncRecorder) RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) error

func (*AsyncRecorder) RecordPromptUsage

func (a *AsyncRecorder) RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) error

func (*AsyncRecorder) RecordTokenUsage

func (a *AsyncRecorder) RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) error

func (*AsyncRecorder) RecordToolUsage

func (a *AsyncRecorder) RecordToolUsage(ctx context.Context, req *ToolUsageRecord) error

func (*AsyncRecorder) Wait

func (a *AsyncRecorder) Wait()

func (*AsyncRecorder) WithInitiatorID

func (a *AsyncRecorder) WithInitiatorID(initiatorID string)

func (*AsyncRecorder) WithMetrics

func (a *AsyncRecorder) WithMetrics(m any)

func (*AsyncRecorder) WithModel

func (a *AsyncRecorder) WithModel(model string)

func (*AsyncRecorder) WithProvider

func (a *AsyncRecorder) WithProvider(provider string)

type InterceptionRecord

type InterceptionRecord struct {
	ID                           string
	InitiatorID, Provider, Model string
	Metadata                     Metadata
	StartedAt                    time.Time
}

type InterceptionRecordEnded

type InterceptionRecordEnded struct {
	ID      string
	EndedAt time.Time
}

type Metadata

type Metadata map[string]any

type PromptUsageRecord

type PromptUsageRecord struct {
	InterceptionID string
	MsgID, Prompt  string
	Metadata       Metadata
	CreatedAt      time.Time
}

type Recorder

type Recorder interface {
	// RecordInterception records metadata about an interception with an upstream AI provider.
	RecordInterception(ctx context.Context, req *InterceptionRecord) error
	// RecordInterceptionEnded records that given interception has completed.
	RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) error
	// RecordTokenUsage records the tokens used in an interception with an upstream AI provider.
	RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) error
	// RecordPromptUsage records the prompts used in an interception with an upstream AI provider.
	RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) error
	// RecordToolUsage records the tools used in an interception with an upstream AI provider.
	RecordToolUsage(ctx context.Context, req *ToolUsageRecord) error
}

Recorder describes all the possible usage information we need to capture during interactions with AI providers. Additionally, it introduces the concept of an "Interception", which includes information about which provider/model was used and by whom. All usage records should reference this Interception by ID.

type RecorderWrapper

type RecorderWrapper struct {
	// contains filtered or unexported fields
}

RecorderWrapper is a convenience struct which implements RecorderClient and resolves a client before calling each method. It also sets the start/creation time of each record.

func NewRecorder

func NewRecorder(logger slog.Logger, tracer trace.Tracer, clientFn func() (Recorder, error)) *RecorderWrapper

func (*RecorderWrapper) RecordInterception

func (r *RecorderWrapper) RecordInterception(ctx context.Context, req *InterceptionRecord) (outErr error)

func (*RecorderWrapper) RecordInterceptionEnded

func (r *RecorderWrapper) RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) (outErr error)

func (*RecorderWrapper) RecordPromptUsage

func (r *RecorderWrapper) RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) (outErr error)

func (*RecorderWrapper) RecordTokenUsage

func (r *RecorderWrapper) RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) (outErr error)

func (*RecorderWrapper) RecordToolUsage

func (r *RecorderWrapper) RecordToolUsage(ctx context.Context, req *ToolUsageRecord) (outErr error)

type TokenUsageRecord

type TokenUsageRecord struct {
	InterceptionID string
	MsgID          string
	Input, Output  int64
	// ExtraTokenTypes holds token types which *may* exist over and above input/output.
	// These should ultimately get merged into [Metadata], but it's useful to keep these
	// with their actual type (int64) since [Metadata] is a map[string]any.
	ExtraTokenTypes map[string]int64
	Metadata        Metadata
	CreatedAt       time.Time
}

type ToolArgs

type ToolArgs any

type ToolUsageRecord

type ToolUsageRecord struct {
	InterceptionID  string
	MsgID, Tool     string
	ServerURL       *string
	Args            ToolArgs
	Injected        bool
	InvocationError error
	Metadata        Metadata
	CreatedAt       time.Time
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL