Documentation
¶
Overview ¶
Package genai provides OpenTelemetry GenAI Semantic Conventions for Aster. Based on: https://opentelemetry.io/docs/specs/semconv/gen-ai/
Index ¶
- Constants
- func AgentSpanName(agentName string) string
- func ChatSpanName(model string) string
- func SpanName(operation string, subject string) string
- func ToolSpanName(toolName string) string
- type AttributeBuilder
- func (b *AttributeBuilder) Build() map[string]any
- func (b *AttributeBuilder) Set(key string, value any) *AttributeBuilder
- func (b *AttributeBuilder) WithAgent(id, name string) *AttributeBuilder
- func (b *AttributeBuilder) WithConversation(id string) *AttributeBuilder
- func (b *AttributeBuilder) WithCost(input, output, total float64, currency string) *AttributeBuilder
- func (b *AttributeBuilder) WithError(errType string) *AttributeBuilder
- func (b *AttributeBuilder) WithLatency(ttft, tpot, total int64) *AttributeBuilder
- func (b *AttributeBuilder) WithModel(model string) *AttributeBuilder
- func (b *AttributeBuilder) WithModelParams(maxTokens int, temperature, topP float64) *AttributeBuilder
- func (b *AttributeBuilder) WithOperation(op string) *AttributeBuilder
- func (b *AttributeBuilder) WithProvider(provider string) *AttributeBuilder
- func (b *AttributeBuilder) WithTokenUsage(input, output int64) *AttributeBuilder
- func (b *AttributeBuilder) WithTool(name, callID string) *AttributeBuilder
Constants ¶
const ( // OpInvokeAgent represents an agent invocation operation OpInvokeAgent = "invoke_agent" // OpCreateAgent represents an agent creation operation OpCreateAgent = "create_agent" // OpChat represents a chat/completion operation OpChat = "chat" // OpGenerateContent represents content generation (Google style) OpGenerateContent = "generate_content" // OpExecuteTool represents a tool execution operation OpExecuteTool = "execute_tool" // OpEmbeddings represents an embeddings operation OpEmbeddings = "embeddings" )
Operation names for GenAI spans
const ( // General operation attributes AttrOperationName = "gen_ai.operation.name" // Provider attributes AttrProviderName = "gen_ai.provider.name" // Agent attributes AttrAgentID = "gen_ai.agent.id" AttrAgentName = "gen_ai.agent.name" AttrAgentDescription = "gen_ai.agent.description" // Conversation/Session attributes AttrConversationID = "gen_ai.conversation.id" AttrThreadID = "gen_ai.thread.id" // alias for conversation_id // Request attributes AttrRequestModel = "gen_ai.request.model" AttrRequestMaxTokens = "gen_ai.request.max_tokens" AttrRequestTemperature = "gen_ai.request.temperature" AttrRequestTopP = "gen_ai.request.top_p" AttrRequestTopK = "gen_ai.request.top_k" AttrRequestStopSequences = "gen_ai.request.stop_sequences" AttrRequestPresencePenalty = "gen_ai.request.presence_penalty" AttrRequestFrequencyPenalty = "gen_ai.request.frequency_penalty" // Response attributes AttrResponseID = "gen_ai.response.id" AttrResponseModel = "gen_ai.response.model" AttrResponseFinishReason = "gen_ai.response.finish_reasons" // Token usage attributes AttrUsageInputTokens = "gen_ai.usage.input_tokens" AttrUsageOutputTokens = "gen_ai.usage.output_tokens" // Tool attributes AttrToolName = "gen_ai.tool.name" AttrToolCallID = "gen_ai.tool.call.id" AttrToolDefinitions = "gen_ai.tool.definitions" // Error attributes AttrErrorType = "error.type" // Performance attributes (Aster-specific extensions) AttrLatencyTTFT = "gen_ai.latency.ttft_ms" // Time to First Token AttrLatencyTPOT = "gen_ai.latency.tpot_ms" // Time Per Output Token AttrLatencyTotal = "gen_ai.latency.total_ms" // Total latency AttrIterationCount = "gen_ai.agent.iteration_count" // Agent loop iterations // Cost attributes (Aster-specific extensions) AttrCostInput = "gen_ai.cost.input" AttrCostOutput = "gen_ai.cost.output" AttrCostTotal = "gen_ai.cost.total" AttrCostCurrency = "gen_ai.cost.currency" )
Attribute keys following OpenTelemetry GenAI Semantic Conventions
const ( ProviderAnthropic = "anthropic" ProviderOpenAI = "openai" ProviderDeepSeek = "deepseek" ProviderGoogle = "gcp.vertex_ai" ProviderAzure = "azure.openai" ProviderBedrock = "aws.bedrock" )
Provider names
const ( ErrorTypeTimeout = "timeout" ErrorTypeRateLimit = "rate_limit" ErrorTypeInvalidRequest = "invalid_request" ErrorTypeAuthentication = "authentication" ErrorTypePermission = "permission" ErrorTypeNotFound = "not_found" ErrorTypeServerError = "server_error" ErrorTypeContentFilter = "content_filter" ErrorTypeContextLengthExceeded = "context_length_exceeded" )
Error types
const ( FinishReasonStop = "stop" FinishReasonLength = "length" FinishReasonToolUse = "tool_use" FinishReasonContentFilter = "content_filter" FinishReasonError = "error" )
Finish reasons
const ( // SpanKindClient should be used for remote LLM calls SpanKindClient = "client" // SpanKindInternal should be used for in-process operations SpanKindInternal = "internal" )
SpanKind constants for GenAI operations
const ( // EventPrompt represents prompt content event EventPrompt = "gen_ai.content.prompt" // EventCompletion represents completion content event EventCompletion = "gen_ai.content.completion" // EventToolCall represents a tool call event EventToolCall = "gen_ai.tool.call" // EventToolResult represents a tool result event EventToolResult = "gen_ai.tool.result" )
EventNames for GenAI semantic events
Variables ¶
This section is empty.
Functions ¶
func AgentSpanName ¶
AgentSpanName generates a span name for agent operations
func ChatSpanName ¶
ChatSpanName generates a span name for chat operations
func ToolSpanName ¶
ToolSpanName generates a span name for tool operations
Types ¶
type AttributeBuilder ¶
type AttributeBuilder struct {
// contains filtered or unexported fields
}
AttributeBuilder helps construct GenAI span attributes
func NewAttributeBuilder ¶
func NewAttributeBuilder() *AttributeBuilder
NewAttributeBuilder creates a new attribute builder
func (*AttributeBuilder) Build ¶
func (b *AttributeBuilder) Build() map[string]any
Build returns the built attributes map
func (*AttributeBuilder) Set ¶
func (b *AttributeBuilder) Set(key string, value any) *AttributeBuilder
Set adds a custom attribute
func (*AttributeBuilder) WithAgent ¶
func (b *AttributeBuilder) WithAgent(id, name string) *AttributeBuilder
WithAgent sets agent-related attributes
func (*AttributeBuilder) WithConversation ¶
func (b *AttributeBuilder) WithConversation(id string) *AttributeBuilder
WithConversation sets the conversation/session ID
func (*AttributeBuilder) WithCost ¶
func (b *AttributeBuilder) WithCost(input, output, total float64, currency string) *AttributeBuilder
WithCost sets cost attributes
func (*AttributeBuilder) WithError ¶
func (b *AttributeBuilder) WithError(errType string) *AttributeBuilder
WithError sets error attributes
func (*AttributeBuilder) WithLatency ¶
func (b *AttributeBuilder) WithLatency(ttft, tpot, total int64) *AttributeBuilder
WithLatency sets latency attributes
func (*AttributeBuilder) WithModel ¶
func (b *AttributeBuilder) WithModel(model string) *AttributeBuilder
WithModel sets the request model
func (*AttributeBuilder) WithModelParams ¶
func (b *AttributeBuilder) WithModelParams(maxTokens int, temperature, topP float64) *AttributeBuilder
WithModelParams sets model parameters
func (*AttributeBuilder) WithOperation ¶
func (b *AttributeBuilder) WithOperation(op string) *AttributeBuilder
WithOperation sets the operation name
func (*AttributeBuilder) WithProvider ¶
func (b *AttributeBuilder) WithProvider(provider string) *AttributeBuilder
WithProvider sets the provider name
func (*AttributeBuilder) WithTokenUsage ¶
func (b *AttributeBuilder) WithTokenUsage(input, output int64) *AttributeBuilder
WithTokenUsage sets token usage attributes
func (*AttributeBuilder) WithTool ¶
func (b *AttributeBuilder) WithTool(name, callID string) *AttributeBuilder
WithTool sets tool-related attributes