Documentation
¶
Index ¶
- Constants
- Variables
- func Attach(mux goahttp.Muxer, service *Service)
- type EventSource
- type FeatureChecker
- type HTTPLogAttributes
- func (h HTTPLogAttributes) RecordDuration(duration float64)
- func (h HTTPLogAttributes) RecordMessageBody(msg string)
- func (h HTTPLogAttributes) RecordMethod(method string)
- func (h HTTPLogAttributes) RecordRequestBody(body int64)
- func (h HTTPLogAttributes) RecordRequestBodyContent(body []byte)
- func (h HTTPLogAttributes) RecordRequestHeaders(headers map[string]string, isSensitive bool)
- func (h HTTPLogAttributes) RecordResponseBody(body int64)
- func (h HTTPLogAttributes) RecordResponseBodyContent(body []byte)
- func (h HTTPLogAttributes) RecordResponseHeaders(headers map[string]string)
- func (h HTTPLogAttributes) RecordRoute(route string)
- func (h HTTPLogAttributes) RecordServerURL(url string, toolType repo.ToolType)
- func (h HTTPLogAttributes) RecordStatusCode(code int)
- func (h HTTPLogAttributes) RecordTraceContext(ctx context.Context)
- func (h HTTPLogAttributes) RecordUserAgent(agent string)
- type LogParams
- type PosthogClient
- type Service
- func (s *Service) APIKeyAuth(ctx context.Context, key string, schema *security.APIKeyScheme) (context.Context, error)
- func (s *Service) CaptureEvent(ctx context.Context, payload *telem_gen.CaptureEventPayload) (res *telem_gen.CaptureEventResult, err error)
- func (s *Service) CheckLogsEnabled(ctx context.Context, organizationID string) error
- func (s *Service) CheckToolIOLogsEnabled(ctx context.Context, organizationID string) bool
- func (s *Service) CreateLog(params LogParams)
- func (s *Service) GetObservabilityOverview(ctx context.Context, payload *telem_gen.GetObservabilityOverviewPayload) (res *telem_gen.GetObservabilityOverviewResult, err error)
- func (s *Service) GetProjectMetricsSummary(ctx context.Context, payload *telem_gen.GetProjectMetricsSummaryPayload) (res *telem_gen.GetMetricsSummaryResult, err error)
- func (s *Service) GetUserMetricsSummary(ctx context.Context, payload *telem_gen.GetUserMetricsSummaryPayload) (res *telem_gen.GetUserMetricsSummaryResult, err error)
- func (s *Service) JWTAuth(ctx context.Context, token string, schema *security.JWTScheme) (context.Context, error)
- func (s *Service) ListAttributeKeys(ctx context.Context, payload *telem_gen.ListAttributeKeysPayload) (res *telem_gen.ListAttributeKeysResult, err error)
- func (s *Service) ListFilterOptions(ctx context.Context, payload *telem_gen.ListFilterOptionsPayload) (res *telem_gen.ListFilterOptionsResult, err error)
- func (s *Service) SearchChats(ctx context.Context, payload *telem_gen.SearchChatsPayload) (res *telem_gen.SearchChatsResult, err error)
- func (s *Service) SearchLogs(ctx context.Context, payload *telem_gen.SearchLogsPayload) (res *telem_gen.SearchLogsResult, err error)
- func (s *Service) SearchToolCalls(ctx context.Context, payload *telem_gen.SearchToolCallsPayload) (res *telem_gen.SearchToolCallsResult, err error)
- func (s *Service) SearchUsers(ctx context.Context, payload *telem_gen.SearchUsersPayload) (res *telem_gen.SearchUsersResult, err error)
- type StubToolMetricsClient
- func (n *StubToolMetricsClient) InsertTelemetryLog(_ context.Context, _ repo.InsertTelemetryLogParams) error
- func (n *StubToolMetricsClient) ListChats(_ context.Context, _ repo.ListChatsParams) ([]repo.ChatSummary, error)
- func (n *StubToolMetricsClient) ListTelemetryLogs(_ context.Context, _ repo.ListTelemetryLogsParams) ([]repo.TelemetryLog, error)
- func (n *StubToolMetricsClient) ListTraces(_ context.Context, _ repo.ListTracesParams) ([]repo.TraceSummary, error)
- type ToolCallLogRoundTripper
- type ToolInfo
Constants ¶
const ( GenAIOperationChat = "chat" GenAIOperationExecuteTool = "execute_tool" )
Variables ¶
var ResourceAttributeKeys = map[attribute.Key]struct{}{ attr.ServiceNameKey: {}, attr.DeploymentIDKey: {}, attr.ServiceVersionKey: {}, }
ResourceAttributeKeys defines which attribute keys should be stored as resource attributes in telemetry logs. Resource attributes describe the entity producing telemetry (service, deployment, project) rather than the specific operation. Based on OTel semantic conventions: https://opentelemetry.io/docs/specs/semconv/resource/
Functions ¶
Types ¶
type EventSource ¶
type EventSource string
EventSource identifies the type of event that generated a telemetry log.
const ( EventSourceToolCall EventSource = "tool_call" EventSourceChatCompletion EventSource = "chat_completion" EventSourceEvaluation EventSource = "evaluation" EventSourceResourceRead EventSource = "resource_read" )
type FeatureChecker ¶
FeatureChecker is a function to determine whether a feature is enabled for an organization.
type HTTPLogAttributes ¶
HTTPLogAttributes is a utility to set attributes in a map.
func (HTTPLogAttributes) RecordDuration ¶
func (h HTTPLogAttributes) RecordDuration(duration float64)
func (HTTPLogAttributes) RecordMessageBody ¶
func (h HTTPLogAttributes) RecordMessageBody(msg string)
func (HTTPLogAttributes) RecordMethod ¶
func (h HTTPLogAttributes) RecordMethod(method string)
func (HTTPLogAttributes) RecordRequestBody ¶
func (h HTTPLogAttributes) RecordRequestBody(body int64)
func (HTTPLogAttributes) RecordRequestBodyContent ¶
func (h HTTPLogAttributes) RecordRequestBodyContent(body []byte)
RecordRequestBodyContent stores the actual tool call input content as an attribute. Content exceeding maxBodyContentBytes is truncated with a marker. Empty bodies are ignored.
func (HTTPLogAttributes) RecordRequestHeaders ¶
func (h HTTPLogAttributes) RecordRequestHeaders(headers map[string]string, isSensitive bool)
func (HTTPLogAttributes) RecordResponseBody ¶
func (h HTTPLogAttributes) RecordResponseBody(body int64)
func (HTTPLogAttributes) RecordResponseBodyContent ¶
func (h HTTPLogAttributes) RecordResponseBodyContent(body []byte)
RecordResponseBodyContent stores the actual tool call output content as an attribute. Content exceeding maxBodyContentBytes is truncated with a marker. Empty bodies are ignored.
func (HTTPLogAttributes) RecordResponseHeaders ¶
func (h HTTPLogAttributes) RecordResponseHeaders(headers map[string]string)
func (HTTPLogAttributes) RecordRoute ¶
func (h HTTPLogAttributes) RecordRoute(route string)
func (HTTPLogAttributes) RecordServerURL ¶
func (h HTTPLogAttributes) RecordServerURL(url string, toolType repo.ToolType)
func (HTTPLogAttributes) RecordStatusCode ¶
func (h HTTPLogAttributes) RecordStatusCode(code int)
func (HTTPLogAttributes) RecordTraceContext ¶
func (h HTTPLogAttributes) RecordTraceContext(ctx context.Context)
RecordTraceContext extracts trace and span IDs from the OTel span context and records them as attributes so they get written to the dedicated ClickHouse columns.
func (HTTPLogAttributes) RecordUserAgent ¶
func (h HTTPLogAttributes) RecordUserAgent(agent string)
type PosthogClient ¶
type PosthogClient interface {
CaptureEvent(ctx context.Context, eventName string, distinctID string, eventProperties map[string]any) error
}
PosthogClient defines the interface for capturing events in PostHog.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService( logger *slog.Logger, db *pgxpool.Pool, chConn clickhouse.Conn, sessions *sessions.Manager, chatSessions *chatsessions.Manager, logsEnabled FeatureChecker, toolIOLogsEnabled FeatureChecker, posthogClient PosthogClient) *Service
NewService creates a telemetry service.
func (*Service) APIKeyAuth ¶
func (*Service) CaptureEvent ¶
func (s *Service) CaptureEvent(ctx context.Context, payload *telem_gen.CaptureEventPayload) (res *telem_gen.CaptureEventResult, err error)
CaptureEvent captures a telemetry event and forwards it to PostHog.
func (*Service) CheckLogsEnabled ¶
CheckLogsEnabled returns whether logs are enabled for the given organization. Returns an error suitable for returning from API endpoints if logs are disabled.
func (*Service) CheckToolIOLogsEnabled ¶
CheckToolIOLogsEnabled returns whether tool I/O logs are enabled for the given organization.
func (*Service) GetObservabilityOverview ¶
func (s *Service) GetObservabilityOverview(ctx context.Context, payload *telem_gen.GetObservabilityOverviewPayload) (res *telem_gen.GetObservabilityOverviewResult, err error)
GetObservabilityOverview retrieves aggregated observability metrics for the overview dashboard.
func (*Service) GetProjectMetricsSummary ¶
func (s *Service) GetProjectMetricsSummary(ctx context.Context, payload *telem_gen.GetProjectMetricsSummaryPayload) (res *telem_gen.GetMetricsSummaryResult, err error)
GetProjectMetricsSummary retrieves aggregated metrics for an entire project.
func (*Service) GetUserMetricsSummary ¶
func (s *Service) GetUserMetricsSummary(ctx context.Context, payload *telem_gen.GetUserMetricsSummaryPayload) (res *telem_gen.GetUserMetricsSummaryResult, err error)
GetUserMetricsSummary retrieves aggregated metrics for a specific user.
func (*Service) ListAttributeKeys ¶
func (s *Service) ListAttributeKeys(ctx context.Context, payload *telem_gen.ListAttributeKeysPayload) (res *telem_gen.ListAttributeKeysResult, err error)
ListAttributeKeys retrieves distinct attribute keys from telemetry logs for the current project.
func (*Service) ListFilterOptions ¶
func (s *Service) ListFilterOptions(ctx context.Context, payload *telem_gen.ListFilterOptionsPayload) (res *telem_gen.ListFilterOptionsResult, err error)
ListFilterOptions retrieves available filter options (API keys or users) for the observability dashboard.
func (*Service) SearchChats ¶
func (s *Service) SearchChats(ctx context.Context, payload *telem_gen.SearchChatsPayload) (res *telem_gen.SearchChatsResult, err error)
SearchChats retrieves chat session summaries with pagination.
func (*Service) SearchLogs ¶
func (s *Service) SearchLogs(ctx context.Context, payload *telem_gen.SearchLogsPayload) (res *telem_gen.SearchLogsResult, err error)
SearchLogs retrieves unified telemetry logs with pagination.
func (*Service) SearchToolCalls ¶
func (s *Service) SearchToolCalls(ctx context.Context, payload *telem_gen.SearchToolCallsPayload) (res *telem_gen.SearchToolCallsResult, err error)
SearchToolCalls retrieves tool call summaries with pagination.
func (*Service) SearchUsers ¶
func (s *Service) SearchUsers(ctx context.Context, payload *telem_gen.SearchUsersPayload) (res *telem_gen.SearchUsersResult, err error)
SearchUsers retrieves user usage summaries grouped by user_id or external_user_id.
type StubToolMetricsClient ¶
type StubToolMetricsClient struct{}
func (*StubToolMetricsClient) InsertTelemetryLog ¶
func (n *StubToolMetricsClient) InsertTelemetryLog(_ context.Context, _ repo.InsertTelemetryLogParams) error
func (*StubToolMetricsClient) ListChats ¶
func (n *StubToolMetricsClient) ListChats(_ context.Context, _ repo.ListChatsParams) ([]repo.ChatSummary, error)
func (*StubToolMetricsClient) ListTelemetryLogs ¶
func (n *StubToolMetricsClient) ListTelemetryLogs(_ context.Context, _ repo.ListTelemetryLogsParams) ([]repo.TelemetryLog, error)
func (*StubToolMetricsClient) ListTraces ¶
func (n *StubToolMetricsClient) ListTraces(_ context.Context, _ repo.ListTracesParams) ([]repo.TraceSummary, error)
type ToolCallLogRoundTripper ¶
type ToolCallLogRoundTripper struct {
AttrRecorder HTTPLogAttributes
// contains filtered or unexported fields
}
ToolCallLogRoundTripper wraps an http.RoundTripper and logs HTTP requests to ClickHouse
func NewToolCallLogRoundTripper ¶
func NewToolCallLogRoundTripper( rt http.RoundTripper, logger *slog.Logger, tracer trace.Tracer, toolInfo ToolInfo, recorder HTTPLogAttributes) *ToolCallLogRoundTripper
NewToolCallLogRoundTripper creates a new RoundTripper that logs HTTP requests to ClickHouse