49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package observability
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// 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
|
|
}
|
|
|