Documentation
¶
Index ¶
- Constants
- func Init(config Config) error
- func InitFromEnv() error
- func InitLangfuse() error
- func Shutdown(ctx context.Context) error
- func StartSpanWithOtel(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- type Config
- type Generation
- func (g *Generation) Finish() *Generation
- func (g *Generation) WithInput(input interface{}) *Generation
- func (g *Generation) WithMetadata(metadata map[string]interface{}) *Generation
- func (g *Generation) WithOutput(output interface{}) *Generation
- func (g *Generation) WithTraceID(traceID string) *Generation
- func (g *Generation) WithUsage(promptTokens, completionTokens int, inputCost, outputCost float64) *Generation
- type LangfuseClient
- type LangfuseConfig
- type LangfuseUsage
- type Score
- type Span
Constants ¶
const ( // Default service name for traces DefaultServiceName = "aixgo" // Langfuse default endpoint LangfuseEndpoint = "https://cloud.langfuse.com/api/public/otel" )
Variables ¶
This section is empty.
Functions ¶
func InitFromEnv ¶
func InitFromEnv() error
InitFromEnv initializes observability from environment variables Supports standard OpenTelemetry environment variables: - OTEL_SERVICE_NAME: Service name (default: "aixgo") - OTEL_TRACES_EXPORTER: Exporter type - "otlp", "stdout", or "none" (default: "otlp") - OTEL_EXPORTER_OTLP_ENDPOINT: OTLP endpoint (default: Langfuse endpoint) - OTEL_EXPORTER_OTLP_HEADERS: Headers in format "key1=value1,key2=value2" - LANGFUSE_PUBLIC_KEY: Langfuse public key (for Basic Auth) - LANGFUSE_SECRET_KEY: Langfuse secret key (for Basic Auth)
func InitLangfuse ¶
func InitLangfuse() error
InitLangfuse initializes the Langfuse client from environment variables
func StartSpanWithOtel ¶
func StartSpanWithOtel(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
StartSpanWithOtel creates a new span with the given name and OpenTelemetry options. This is the preferred method for context-aware tracing. Returns a context with the span and the raw OpenTelemetry span.
Types ¶
type Config ¶
type Config struct {
// ServiceName is the name of the service (defaults to "aixgo")
ServiceName string
// Enabled controls whether tracing is enabled (defaults to true)
Enabled bool
// ExporterType specifies the exporter: "otlp", "stdout", or "none"
ExporterType string
// OTLPEndpoint is the OTLP endpoint URL (defaults to Langfuse)
OTLPEndpoint string
// OTLPHeaders are additional headers for OTLP requests (e.g., authorization)
OTLPHeaders map[string]string
}
Config holds observability configuration
type Generation ¶
type Generation struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime,omitempty"`
Model string `json:"model"`
ModelParameters map[string]interface{} `json:"modelParameters,omitempty"`
Input interface{} `json:"input,omitempty"`
Output interface{} `json:"output,omitempty"`
Usage *LangfuseUsage `json:"usage,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Level string `json:"level,omitempty"` // "DEBUG", "DEFAULT", "WARNING", "ERROR"
StatusMessage string `json:"statusMessage,omitempty"`
Version string `json:"version,omitempty"`
TraceID string `json:"traceId,omitempty"`
ParentID string `json:"parentObservationId,omitempty"`
}
Generation represents an LLM generation event in Langfuse
func NewGeneration ¶
func NewGeneration(name, model string, startTime time.Time) *Generation
NewGeneration creates a new Generation event
func (*Generation) Finish ¶
func (g *Generation) Finish() *Generation
Finish marks the generation as complete
func (*Generation) WithInput ¶
func (g *Generation) WithInput(input interface{}) *Generation
WithInput adds input to a generation
func (*Generation) WithMetadata ¶
func (g *Generation) WithMetadata(metadata map[string]interface{}) *Generation
WithMetadata adds metadata to a generation
func (*Generation) WithOutput ¶
func (g *Generation) WithOutput(output interface{}) *Generation
WithOutput adds output to a generation
func (*Generation) WithTraceID ¶
func (g *Generation) WithTraceID(traceID string) *Generation
WithTraceID associates the generation with a trace
func (*Generation) WithUsage ¶
func (g *Generation) WithUsage(promptTokens, completionTokens int, inputCost, outputCost float64) *Generation
WithUsage adds usage information to a generation
type LangfuseClient ¶
type LangfuseClient struct {
// contains filtered or unexported fields
}
LangfuseClient provides direct integration with Langfuse SDK features beyond what's available through OpenTelemetry. This includes LLM-specific features like Generations, Scores, and Feedback.
var ( // DefaultLangfuseClient is the global Langfuse client instance DefaultLangfuseClient *LangfuseClient )
func NewLangfuseClient ¶
func NewLangfuseClient(config LangfuseConfig) (*LangfuseClient, error)
NewLangfuseClient creates a new Langfuse client
func (*LangfuseClient) Close ¶
func (c *LangfuseClient) Close() error
Close closes the Langfuse client
func (*LangfuseClient) Flush ¶
func (c *LangfuseClient) Flush(ctx context.Context) error
Flush ensures all pending events are sent (no-op for HTTP client)
func (*LangfuseClient) TrackGeneration ¶
func (c *LangfuseClient) TrackGeneration(ctx context.Context, gen *Generation) error
TrackGeneration tracks an LLM generation in Langfuse
func (*LangfuseClient) TrackScore ¶
func (c *LangfuseClient) TrackScore(ctx context.Context, score *Score) error
TrackScore tracks a score/evaluation in Langfuse
type LangfuseConfig ¶
type LangfuseConfig struct {
// BaseURL is the Langfuse API endpoint (defaults to cloud.langfuse.com)
BaseURL string
// PublicKey is the Langfuse public key
PublicKey string
// SecretKey is the Langfuse secret key
SecretKey string
// Enabled controls whether Langfuse integration is active
Enabled bool
}
LangfuseConfig contains configuration for Langfuse integration
type LangfuseUsage ¶
type LangfuseUsage struct {
PromptTokens int `json:"promptTokens,omitempty"`
CompletionTokens int `json:"completionTokens,omitempty"`
TotalTokens int `json:"totalTokens,omitempty"`
Unit string `json:"unit,omitempty"` // "TOKENS", "CHARACTERS", "MILLISECONDS", etc.
InputCost float64 `json:"inputCost,omitempty"`
OutputCost float64 `json:"outputCost,omitempty"`
TotalCost float64 `json:"totalCost,omitempty"`
}
LangfuseUsage represents token usage and cost
type Score ¶
type Score struct {
ID string `json:"id,omitempty"`
TraceID string `json:"traceId"`
Name string `json:"name"`
Value float64 `json:"value"`
Comment string `json:"comment,omitempty"`
ObservationID string `json:"observationId,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Score represents a score/evaluation for a trace or generation
func (*Score) WithComment ¶
WithComment adds a comment to a score
func (*Score) WithObservationID ¶
WithObservationID associates the score with a specific observation
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
Span represents an observability span
func StartSpan ¶
StartSpan creates a new span with the given name and attributes (legacy version with map) Deprecated: Use StartSpanWithContext for context-aware tracing
func StartSpanWithContext ¶
func StartSpanWithContext(ctx context.Context, name string, data map[string]any) (context.Context, *Span)
StartSpanWithContext creates a new span from a parent context
func (*Span) SetAttribute ¶
SetAttribute adds an attribute to the span