Files
defiQUG 9839401d1d
Some checks failed
CI / build (push) Has been cancelled
TTS: configurable auth, Health check, Phoenix options; .env.example; Gitea CI workflow
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-10 16:54:10 -08:00

48 lines
1.2 KiB
Go

package observability
import (
"context"
)
// Tracer provides distributed tracing
type Tracer interface {
StartSpan(ctx context.Context, name string) (context.Context, Span)
}
// Span represents a tracing span
type Span interface {
End()
SetAttribute(key string, value interface{})
SetError(err error)
}
// MockTracer is a mock tracer for development
type MockTracer struct{}
// StartSpan starts a new span
func (t *MockTracer) StartSpan(ctx context.Context, name string) (context.Context, Span) {
return ctx, &MockSpan{}
}
// MockSpan is a mock span
type MockSpan struct{}
// End ends the span
func (m *MockSpan) End() {}
// SetAttribute sets an attribute
func (m *MockSpan) SetAttribute(key string, value interface{}) {}
// SetError sets an error
func (m *MockSpan) SetError(err error) {}
// TraceConversation traces a conversation turn
func TraceConversation(ctx context.Context, tracer Tracer, sessionID, userID string, input string) (context.Context, Span) {
ctx, span := tracer.StartSpan(ctx, "conversation.turn")
span.SetAttribute("session_id", sessionID)
span.SetAttribute("user_id", userID)
span.SetAttribute("input_length", len(input))
return ctx, span
}