Documentation
¶
Overview ¶
Package langfuse provides a Go client library for interacting with the Langfuse platform.
This package offers comprehensive support for observability tracing, prompt management, model configuration, datasets, sessions, scores, projects, LLM connections, comments, and annotations functionality with efficient batch processing.
Basic usage:
client := langfuse.NewClient("https://cloud.langfuse.com", "your-public-key", "your-secret-key")
defer client.Close()
trace := client.StartTrace("my-application")
span := trace.StartSpan("processing-step")
// ... your application logic
span.End()
trace.End()
Index ¶
- type ClientOption
- type Langfuse
- func (c *Langfuse) Close() error
- func (c *Langfuse) Comments() *comments.Client
- func (c *Langfuse) Datasets() *datasets.Client
- func (c *Langfuse) Flush()
- func (c *Langfuse) Health() *health.Client
- func (c *Langfuse) LLMConnections() *llmconnections.Client
- func (c *Langfuse) Media() *media.Client
- func (c *Langfuse) Models() *models.Client
- func (c *Langfuse) Organizations() *organizations.Client
- func (c *Langfuse) Projects() *projects.Client
- func (c *Langfuse) Prompts() *prompts.Client
- func (c *Langfuse) Scores() *scores.Client
- func (c *Langfuse) Sessions() *sessions.Client
- func (c *Langfuse) StartTrace(ctx context.Context, name string) *traces.Trace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientOption ¶ added in v0.0.4
type ClientOption func(*clientConfig)
ClientOption is a function that configures a Langfuse client.
func WithHTTPClient ¶ added in v0.0.4
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient sets a custom HTTP client for the Langfuse client.
This allows you to customize timeout settings, transport configuration, and other HTTP client behavior. If not provided, resty will use its default HTTP client.
Example:
httpClient := &http.Client{
Timeout: 30 * time.Second,
Transport: &http.Transport{
MaxIdleConns: 100,
MaxIdleConnsPerHost: 10,
},
}
client := langfuse.NewClient("https://cloud.langfuse.com", "public-key", "secret-key", langfuse.WithHTTPClient(httpClient))
type Langfuse ¶ added in v0.0.3
type Langfuse struct {
// contains filtered or unexported fields
}
Langfuse is the main client for interacting with the Langfuse platform.
It provides access to all Langfuse functionality including tracing, prompts, models, datasets, sessions, scores, projects, LLM connections, comments, and annotations through dedicated client instances.
The client manages HTTP connections and provides efficient batch processing for trace ingestion with automatic flushing and graceful shutdown capabilities.
func NewClient ¶
func NewClient(host string, publicKey string, secretKey string, options ...ClientOption) *Langfuse
NewClient creates a new Langfuse client instance with the specified host and credentials.
The host should be the base URL of your Langfuse instance (e.g., "https://cloud.langfuse.com"). The publicKey and secretKey are obtained from your Langfuse project settings. Optional configuration can be provided using ClientOption functions.
The client automatically configures HTTP basic authentication and sets the API base URL. Remember to call Close() when done to ensure all pending traces are flushed.
Example with custom HTTP client:
httpClient := &http.Client{Timeout: 30 * time.Second}
client := langfuse.NewClient("https://cloud.langfuse.com", "public-key", "secret-key", langfuse.WithHTTPClient(httpClient))
func (*Langfuse) Close ¶ added in v0.0.3
Close gracefully shuts down the client and flushes all pending traces.
This method ensures that all batched traces are sent to Langfuse before the client is closed. It should be called when you're done using the client, typically in a defer statement.
Returns an error if the shutdown process fails or times out.
func (*Langfuse) Comments ¶ added in v0.0.3
Comments returns a client for managing comments on traces, observations, and sessions.
Use this client to add contextual comments to your traces and observations for collaboration and debugging purposes.
func (*Langfuse) Datasets ¶ added in v0.0.3
Datasets returns a client for managing datasets and dataset items.
Use this client to create and manage datasets for training, evaluation, and testing of your AI models, including dataset items and runs.
func (*Langfuse) Health ¶ added in v0.0.3
Health returns a client for checking API health status and version.
Use this client to verify connectivity and server status.
func (*Langfuse) LLMConnections ¶ added in v0.0.3
func (c *Langfuse) LLMConnections() *llmconnections.Client
LLMConnections returns a client for managing LLM provider connections.
Use this client to configure connections to various LLM providers like OpenAI, Anthropic, Azure OpenAI, AWS Bedrock, and Google Vertex AI.
func (*Langfuse) Media ¶ added in v0.0.3
Media returns a client for managing media files associated with traces and observations.
Use this client to upload, retrieve, and manage media files including images, audio, video, and documents. Media files are associated with traces and observations through their input, output, or metadata fields.
func (*Langfuse) Models ¶ added in v0.0.3
Models returns a client for managing model configurations and pricing.
Use this client to define model pricing, match patterns, and manage model metadata for cost tracking and analytics.
func (*Langfuse) Organizations ¶ added in v0.0.3
func (c *Langfuse) Organizations() *organizations.Client
Organizations returns a client for managing organization and project memberships.
Use this client to manage user roles and permissions within organizations and projects. Most operations require organization-scoped API keys.
func (*Langfuse) Projects ¶ added in v0.0.3
Projects returns a client for managing projects and API keys.
Use this client to create, update, and manage projects, as well as manage API keys within projects. Most operations require organization-scoped API keys.
func (*Langfuse) Prompts ¶ added in v0.0.3
Prompts returns a client for managing prompt templates and versions.
Use this client to create, retrieve, list, and manage prompt templates for your AI applications.
func (*Langfuse) Scores ¶ added in v0.0.3
Scores returns a client for managing evaluation scores and score configurations.
Use this client to create, retrieve, and manage scores for your traces and observations, including score configurations for different data types.
func (*Langfuse) Sessions ¶ added in v0.0.3
Sessions returns a client for managing user sessions and their associated traces.
Use this client to retrieve and analyze user sessions, including filtering by time ranges and environments.
func (*Langfuse) StartTrace ¶ added in v0.0.3
StartTrace creates a new trace with the given name.
A trace represents a single execution flow in your application and can contain multiple observations (spans). Traces are automatically batched and sent to Langfuse for efficient ingestion.
Returns a Trace instance that you can use to add observations and metadata.
Directories
¶
| Path | Synopsis |
|---|---|
|
pkg
|
|
|
annotations
Package annotations provides functionality for managing annotation queues and items in Langfuse.
|
Package annotations provides functionality for managing annotation queues and items in Langfuse. |
|
batch
Package batch provides a generic, type-safe batch processor for efficient API ingestion.
|
Package batch provides a generic, type-safe batch processor for efficient API ingestion. |
|
comments
Package comments provides functionality for managing comments on traces, observations, and sessions in Langfuse.
|
Package comments provides functionality for managing comments on traces, observations, and sessions in Langfuse. |
|
common
Package common provides shared types and utilities for HTTP operations across all Langfuse clients.
|
Package common provides shared types and utilities for HTTP operations across all Langfuse clients. |
|
datasets
Package datasets provides functionality for managing datasets and dataset items in Langfuse.
|
Package datasets provides functionality for managing datasets and dataset items in Langfuse. |
|
health
Package health provides functionality to check the Langfuse API health.
|
Package health provides functionality to check the Langfuse API health. |
|
llmconnections
Package llmconnections provides functionality for managing LLM provider connections in Langfuse.
|
Package llmconnections provides functionality for managing LLM provider connections in Langfuse. |
|
logger
Package logger provides a global zap logger instance for JSON formatted logging across the entire langfuse-go project.
|
Package logger provides a global zap logger instance for JSON formatted logging across the entire langfuse-go project. |
|
media
Package media provides functionality for managing media records in Langfuse.
|
Package media provides functionality for managing media records in Langfuse. |
|
models
Package models provides functionality for managing model configurations and pricing in Langfuse.
|
Package models provides functionality for managing model configurations and pricing in Langfuse. |
|
organizations
Package organizations provides functionality for managing organization and project memberships in Langfuse.
|
Package organizations provides functionality for managing organization and project memberships in Langfuse. |
|
projects
Package projects provides functionality for managing projects and API keys in Langfuse.
|
Package projects provides functionality for managing projects and API keys in Langfuse. |
|
prompts
Package prompts provides functionality for managing prompt templates and versions in Langfuse.
|
Package prompts provides functionality for managing prompt templates and versions in Langfuse. |
|
scores
Package scores provides functionality for managing evaluation scores and score configurations in Langfuse.
|
Package scores provides functionality for managing evaluation scores and score configurations in Langfuse. |
|
sessions
Package sessions provides functionality for managing user sessions and their associated traces in Langfuse.
|
Package sessions provides functionality for managing user sessions and their associated traces in Langfuse. |
|
traces
Package traces provides functionality for distributed tracing in Langfuse.
|
Package traces provides functionality for distributed tracing in Langfuse. |