genai

package
v0.35.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package genai provides OpenTelemetry GenAI Semantic Conventions for Aster. Based on: https://opentelemetry.io/docs/specs/semconv/gen-ai/

Index

Constants

View Source
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

View Source
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

View Source
const (
	ProviderAnthropic = "anthropic"
	ProviderOpenAI    = "openai"
	ProviderDeepSeek  = "deepseek"
	ProviderGoogle    = "gcp.vertex_ai"
	ProviderAzure     = "azure.openai"
	ProviderBedrock   = "aws.bedrock"
)

Provider names

View Source
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

View Source
const (
	FinishReasonStop          = "stop"
	FinishReasonLength        = "length"
	FinishReasonToolUse       = "tool_use"
	FinishReasonContentFilter = "content_filter"
	FinishReasonError         = "error"
)

Finish reasons

View Source
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

View Source
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

func AgentSpanName(agentName string) string

AgentSpanName generates a span name for agent operations

func ChatSpanName

func ChatSpanName(model string) string

ChatSpanName generates a span name for chat operations

func SpanName

func SpanName(operation string, subject string) string

SpanName generates a standardized span name for GenAI operations

func ToolSpanName

func ToolSpanName(toolName string) string

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL