telemetry

package
v0.0.62 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttrSpeechID   = "lk.speech_id"
	AttrAgentLabel = "lk.agent_label"
	AttrStartTime  = "lk.start_time"
	AttrEndTime    = "lk.end_time"
	AttrRetryCount = "lk.retry_count"

	AttrParticipantID       = "lk.participant_id"
	AttrParticipantIdentity = "lk.participant_identity"
	AttrParticipantKind     = "lk.participant_kind"

	AttrJobID          = "lk.job_id"
	AttrAgentName      = "lk.agent_name"
	AttrRoomName       = "lk.room_name"
	AttrSessionOptions = "lk.session_options"

	AttrAgentTurnID       = "lk.generation_id"
	AttrAgentParentTurnID = "lk.parent_generation_id"
	AttrUserInput         = "lk.user_input"
	AttrInstructions      = "lk.instructions"
	AttrSpeechInterrupted = "lk.interrupted"

	AttrChatCtx               = "lk.chat_ctx"
	AttrFunctionTools         = "lk.function_tools"
	AttrProviderTools         = "lk.provider_tools"
	AttrToolSets              = "lk.tool_sets"
	AttrResponseText          = "lk.response.text"
	AttrResponseFunctionCalls = "lk.response.function_calls"
	AttrResponseTTFB          = "lk.response.ttfb"

	AttrFunctionToolID      = "lk.function_tool.id"
	AttrFunctionToolName    = "lk.function_tool.name"
	AttrFunctionToolArgs    = "lk.function_tool.arguments"
	AttrFunctionToolIsError = "lk.function_tool.is_error"
	AttrFunctionToolOutput  = "lk.function_tool.output"

	AttrTTSInputText = "lk.input_text"
	AttrTTSStreaming = "lk.tts.streaming"
	AttrTTSLabel     = "lk.tts.label"

	AttrEOUProbability       = "lk.eou.probability"
	AttrEOUUnlikelyThreshold = "lk.eou.unlikely_threshold"
	AttrEOUDelay             = "lk.eou.endpointing_delay"
	AttrEOULanguage          = "lk.eou.language"
	AttrUserTranscript       = "lk.user_transcript"
	AttrTranscriptConfidence = "lk.transcript_confidence"
	AttrTranscriptionDelay   = "lk.transcription_delay"
	AttrEndOfTurnDelay       = "lk.end_of_turn_delay"

	AttrGenAIOperationName     = "gen_ai.operation.name"
	AttrGenAIProviderName      = "gen_ai.provider.name"
	AttrGenAIRequestModel      = "gen_ai.request.model"
	AttrGenAIUsageInputTokens  = "gen_ai.usage.input_tokens"
	AttrGenAIUsageOutputTokens = "gen_ai.usage.output_tokens"

	EventGenAISystemMessage    = "gen_ai.system.message"
	EventGenAIUserMessage      = "gen_ai.user.message"
	EventGenAIAssistantMessage = "gen_ai.assistant.message"
	EventGenAIToolMessage      = "gen_ai.tool.message"
	EventGenAIChoice           = "gen_ai.choice"
)

Variables

View Source
var ChatLogger log.Logger
View Source
var Tracer = otel.Tracer("livekit-agents")

Functions

func AddChatTraceEvents added in v0.0.15

func AddChatTraceEvents(span trace.Span, events []ChatTraceEvent)

func CollectOTelUsage added in v0.0.15

func CollectOTelUsage(metrics AgentMetrics)

func CollectOTelUsageWithContext added in v0.0.15

func CollectOTelUsageWithContext(ctx context.Context, metrics AgentMetrics)

func InitLoggerProvider

func InitLoggerProvider(ctx context.Context, endpoint string, headers map[string]string) error

func LogMetrics

func LogMetrics(metrics AgentMetrics)

func NewLLMSpan

func NewLLMSpan(ctx context.Context, model, provider string) (context.Context, trace.Span)

func NewSTTStreamSpan

func NewSTTStreamSpan(ctx context.Context, model, provider string) (context.Context, trace.Span)

func NewTTSNodeSpan added in v0.0.15

func NewTTSNodeSpan(ctx context.Context, model, provider string) (context.Context, trace.Span)

func NewTTSStreamSpan

func NewTTSStreamSpan(ctx context.Context, model, provider string) (context.Context, trace.Span)

func RecordChatEvent

func RecordChatEvent(ctx context.Context, eventType string, body string, attributes map[string]interface{})

func RecordChatEventAt added in v0.0.19

func RecordChatEventAt(ctx context.Context, eventType string, body string, attributes map[string]interface{}, timestamp time.Time)

func RecordChatEventWithOptions added in v0.0.19

func RecordChatEventWithOptions(ctx context.Context, eventType string, body string, attributes map[string]interface{}, options ChatEventOptions)

func RecordOTelTurnMetrics added in v0.0.15

func RecordOTelTurnMetrics(report map[string]any)

func RecordOTelTurnMetricsWithContext added in v0.0.15

func RecordOTelTurnMetricsWithContext(ctx context.Context, report map[string]any)

func ShutdownLoggerProvider

func ShutdownLoggerProvider(ctx context.Context) error

func StartSpan

func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

Types

type AgentMetrics

type AgentMetrics interface {
	GetType() string
}

type AgentSessionUsage added in v0.0.15

type AgentSessionUsage struct {
	ModelUsage []ModelUsage `json:"model_usage"`
}

func (AgentSessionUsage) LLMInputTokens added in v0.0.15

func (s AgentSessionUsage) LLMInputTokens() int

func (AgentSessionUsage) LLMOutputTokens added in v0.0.15

func (s AgentSessionUsage) LLMOutputTokens() int

type AvatarMetrics added in v0.0.15

type AvatarMetrics struct {
	Label              string
	Timestamp          time.Time
	PlaybackLatency    float64
	SessionStartedTime *time.Time
	AvatarJoinedTime   *time.Time
	Metadata           *Metadata
}

func (*AvatarMetrics) GetType added in v0.0.15

func (m *AvatarMetrics) GetType() string

func (*AvatarMetrics) MarshalJSON added in v0.0.52

func (m *AvatarMetrics) MarshalJSON() ([]byte, error)

type CachedTokenDetails

type CachedTokenDetails struct {
	AudioTokens int
	TextTokens  int
	ImageTokens int
}

func (CachedTokenDetails) MarshalJSON added in v0.0.52

func (d CachedTokenDetails) MarshalJSON() ([]byte, error)

type ChatEventOptions added in v0.0.19

type ChatEventOptions struct {
	Timestamp    time.Time
	Severity     log.Severity
	SeverityText string
}

func ErrorChatEventOptions added in v0.0.19

func ErrorChatEventOptions(timestamp time.Time) ChatEventOptions

type ChatTraceEvent added in v0.0.15

type ChatTraceEvent struct {
	Name       string
	Attributes []attribute.KeyValue
}

type EOUMetrics

type EOUMetrics struct {
	Timestamp                time.Time
	EndOfUtteranceDelay      float64
	TranscriptionDelay       float64
	OnUserTurnCompletedDelay float64
	SpeechID                 string
	Metadata                 *Metadata
}

func (*EOUMetrics) GetType

func (m *EOUMetrics) GetType() string

func (*EOUMetrics) MarshalJSON added in v0.0.52

func (m *EOUMetrics) MarshalJSON() ([]byte, error)

type HttpServer

type HttpServer struct {
	Host string
	Port int
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer(host string, port int) *HttpServer

func NewHttpServerWithListen added in v0.0.15

func NewHttpServerWithListen(host string, port int, listen func(network, address string) (net.Listener, error)) *HttpServer

func (*HttpServer) Start

func (s *HttpServer) Start() error

func (*HttpServer) Stop

func (s *HttpServer) Stop(ctx context.Context) error

type InputTokenDetails

type InputTokenDetails struct {
	AudioTokens         int
	TextTokens          int
	ImageTokens         int
	CachedTokens        int
	CachedTokensDetails *CachedTokenDetails
}

func (InputTokenDetails) MarshalJSON added in v0.0.52

func (d InputTokenDetails) MarshalJSON() ([]byte, error)

type InterruptionMetrics added in v0.0.15

type InterruptionMetrics struct {
	Label              string
	Timestamp          time.Time
	TotalDuration      float64
	PredictionDuration float64
	DetectionDelay     float64
	NumInterruptions   int
	NumBackchannels    int
	NumRequests        int
	Metadata           *Metadata
}

func (*InterruptionMetrics) GetType added in v0.0.15

func (m *InterruptionMetrics) GetType() string

func (*InterruptionMetrics) MarshalJSON added in v0.0.52

func (m *InterruptionMetrics) MarshalJSON() ([]byte, error)

type InterruptionModelUsage added in v0.0.15

type InterruptionModelUsage struct {
	Type          string `json:"type"`
	Provider      string `json:"provider"`
	Model         string `json:"model"`
	TotalRequests int    `json:"total_requests"`
}

func (*InterruptionModelUsage) GetType added in v0.0.15

func (u *InterruptionModelUsage) GetType() string

type LLMMetrics

type LLMMetrics struct {
	Label              string
	RequestID          string
	Timestamp          time.Time
	Duration           float64
	TTFT               float64
	Cancelled          bool
	CompletionTokens   int
	PromptTokens       int
	PromptCachedTokens int
	TotalTokens        int
	TokensPerSecond    float64
	SpeechID           string
	Metadata           *Metadata
}

func (*LLMMetrics) GetType

func (m *LLMMetrics) GetType() string

func (*LLMMetrics) MarshalJSON added in v0.0.52

func (m *LLMMetrics) MarshalJSON() ([]byte, error)

type LLMModelUsage added in v0.0.15

type LLMModelUsage struct {
	Type                   string  `json:"type"`
	Provider               string  `json:"provider"`
	Model                  string  `json:"model"`
	InputTokens            int     `json:"input_tokens"`
	InputCachedTokens      int     `json:"input_cached_tokens"`
	InputAudioTokens       int     `json:"input_audio_tokens"`
	InputCachedAudioTokens int     `json:"input_cached_audio_tokens"`
	InputTextTokens        int     `json:"input_text_tokens"`
	InputCachedTextTokens  int     `json:"input_cached_text_tokens"`
	InputImageTokens       int     `json:"input_image_tokens"`
	InputCachedImageTokens int     `json:"input_cached_image_tokens"`
	OutputTokens           int     `json:"output_tokens"`
	OutputAudioTokens      int     `json:"output_audio_tokens"`
	OutputTextTokens       int     `json:"output_text_tokens"`
	SessionDuration        float64 `json:"session_duration"`
}

func (*LLMModelUsage) GetType added in v0.0.15

func (u *LLMModelUsage) GetType() string

type Metadata

type Metadata struct {
	ModelName     string
	ModelProvider string
}

func (*Metadata) MarshalJSON added in v0.0.52

func (m *Metadata) MarshalJSON() ([]byte, error)

type MetricLabels

type MetricLabels struct {
	AgentName           string
	AgentVersion        string
	RoomName            string
	ParticipantIdentity string
}

type MetricRegistry

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

func NewMetricRegistry

func NewMetricRegistry() *MetricRegistry

func (*MetricRegistry) GetUsageCollector

func (r *MetricRegistry) GetUsageCollector(labels MetricLabels) *UsageCollector

type ModelUsage added in v0.0.15

type ModelUsage interface {
	GetType() string
}

type ModelUsageCollector added in v0.0.15

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

func NewModelUsageCollector added in v0.0.15

func NewModelUsageCollector() *ModelUsageCollector

func (*ModelUsageCollector) Collect added in v0.0.15

func (c *ModelUsageCollector) Collect(metrics AgentMetrics)

func (*ModelUsageCollector) Flatten added in v0.0.15

func (c *ModelUsageCollector) Flatten() []ModelUsage

func (*ModelUsageCollector) Usage added in v0.0.15

type OutputTokenDetails

type OutputTokenDetails struct {
	TextTokens  int
	AudioTokens int
	ImageTokens int
}

func (OutputTokenDetails) MarshalJSON added in v0.0.52

func (d OutputTokenDetails) MarshalJSON() ([]byte, error)

type RealtimeModelMetrics

type RealtimeModelMetrics struct {
	Label              string
	RequestID          string
	Timestamp          time.Time
	Duration           float64
	SessionDuration    float64
	TTFT               float64
	Cancelled          bool
	InputTokens        int
	OutputTokens       int
	TotalTokens        int
	TokensPerSecond    float64
	InputTokenDetails  InputTokenDetails
	OutputTokenDetails OutputTokenDetails
	AcquireTime        float64
	ConnectionReused   bool
	Metadata           *Metadata
}

func (*RealtimeModelMetrics) GetType

func (m *RealtimeModelMetrics) GetType() string

func (*RealtimeModelMetrics) MarshalJSON added in v0.0.52

func (m *RealtimeModelMetrics) MarshalJSON() ([]byte, error)

type STTMetrics

type STTMetrics struct {
	Label            string
	RequestID        string
	Timestamp        time.Time
	Duration         float64
	AudioDuration    float64
	InputTokens      int
	OutputTokens     int
	Streamed         bool
	AcquireTime      float64
	ConnectionReused bool
	Metadata         *Metadata
}

func (*STTMetrics) GetType

func (m *STTMetrics) GetType() string

func (*STTMetrics) MarshalJSON added in v0.0.52

func (m *STTMetrics) MarshalJSON() ([]byte, error)

type STTModelUsage added in v0.0.15

type STTModelUsage struct {
	Type          string  `json:"type"`
	Provider      string  `json:"provider"`
	Model         string  `json:"model"`
	InputTokens   int     `json:"input_tokens"`
	OutputTokens  int     `json:"output_tokens"`
	AudioDuration float64 `json:"audio_duration"`
}

func (*STTModelUsage) GetType added in v0.0.15

func (u *STTModelUsage) GetType() string

type SpanContext

type SpanContext struct {
	SpeechID string
	Span     trace.Span
}

type TTSMetrics

type TTSMetrics struct {
	Label            string
	RequestID        string
	Timestamp        time.Time
	TTFB             float64
	Duration         float64
	AudioDuration    float64
	Cancelled        bool
	CharactersCount  int
	InputTokens      int
	OutputTokens     int
	Streamed         bool
	SegmentID        string
	SpeechID         string
	AcquireTime      float64
	ConnectionReused bool
	Metadata         *Metadata
}

func (*TTSMetrics) GetType

func (m *TTSMetrics) GetType() string

func (*TTSMetrics) MarshalJSON added in v0.0.52

func (m *TTSMetrics) MarshalJSON() ([]byte, error)

type TTSModelUsage added in v0.0.15

type TTSModelUsage struct {
	Type            string  `json:"type"`
	Provider        string  `json:"provider"`
	Model           string  `json:"model"`
	InputTokens     int     `json:"input_tokens"`
	OutputTokens    int     `json:"output_tokens"`
	CharactersCount int     `json:"characters_count"`
	AudioDuration   float64 `json:"audio_duration"`
}

func (*TTSModelUsage) GetType added in v0.0.15

func (u *TTSModelUsage) GetType() string

type UsageCollector

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

func NewUsageCollector

func NewUsageCollector() *UsageCollector

func (*UsageCollector) Collect

func (c *UsageCollector) Collect(metrics AgentMetrics)

func (*UsageCollector) GetSummary

func (c *UsageCollector) GetSummary() UsageSummary

type UsageSummary

type UsageSummary struct {
	LLMPromptTokens           int
	LLMPromptCachedTokens     int
	LLMInputAudioTokens       int
	LLMInputCachedAudioTokens int
	LLMInputTextTokens        int
	LLMInputCachedTextTokens  int
	LLMInputImageTokens       int
	LLMInputCachedImageTokens int
	LLMCompletionTokens       int
	LLMOutputAudioTokens      int
	LLMOutputImageTokens      int
	LLMOutputTextTokens       int
	TTSCharactersCount        int
	TTSAudioDuration          float64
	STTAudioDuration          float64
}

func (UsageSummary) LLMInputTokens added in v0.0.15

func (s UsageSummary) LLMInputTokens() int

func (UsageSummary) LLMOutputTokens added in v0.0.15

func (s UsageSummary) LLMOutputTokens() int

func (*UsageSummary) SetLLMInputTokens added in v0.0.15

func (s *UsageSummary) SetLLMInputTokens(value int)

func (*UsageSummary) SetLLMOutputTokens added in v0.0.15

func (s *UsageSummary) SetLLMOutputTokens(value int)

type VADMetrics

type VADMetrics struct {
	Label                  string
	Timestamp              time.Time
	IdleTime               float64
	InferenceDurationTotal float64
	InferenceCount         int
	Metadata               *Metadata
}

func (*VADMetrics) GetType

func (m *VADMetrics) GetType() string

func (*VADMetrics) MarshalJSON added in v0.0.52

func (m *VADMetrics) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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