Add full monorepo: virtual-banker, backend, frontend, docs, scripts, deployment
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
48
backend/observability/tracing.go
Normal file
48
backend/observability/tracing.go
Normal file
@@ -0,0 +1,48 @@
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user