Documentation
¶
Overview ¶
Package langfuse is an OpenTelemetry-backed client for Langfuse. Trace, Generation, Span, and Event observations are exported as OTel spans via OTLP HTTP to /api/public/otel/v1/traces. Prompts and Scores continue to use Langfuse's REST endpoints.
The SDK builds its own TracerProvider and never registers it as the global provider, so it can run alongside other OTel pipelines (e.g. Sentry) without cross-pollination.
Index ¶
- type GetPromptOptions
- type Langfuse
- func (l *Langfuse) ClearPromptCache()
- func (l *Langfuse) DeleteScore(ctx context.Context, scoreID string) error
- func (l *Langfuse) Event(e *model.Event, parentID *string) (*model.Event, error)
- func (l *Langfuse) Flush(ctx context.Context)
- func (l *Langfuse) Generation(g *model.Generation, parentID *string) (*model.Generation, error)
- func (l *Langfuse) GenerationEnd(g *model.Generation) (*model.Generation, error)
- func (l *Langfuse) GetPrompt(ctx context.Context, name string, opts *GetPromptOptions) (*model.Prompt, error)
- func (l *Langfuse) Score(s *model.Score) (*model.Score, error)
- func (l *Langfuse) Shutdown(ctx context.Context) error
- func (l *Langfuse) Span(s *model.Span, parentID *string) (*model.Span, error)
- func (l *Langfuse) SpanEnd(s *model.Span) (*model.Span, error)
- func (l *Langfuse) Trace(t *model.Trace) (*model.Trace, error)
- func (l *Langfuse) TraceEnd(traceID string) error
- func (l *Langfuse) WithFlushInterval(_ time.Duration) *Langfuse
- func (l *Langfuse) WithPromptCacheTTL(ttl time.Duration) *Langfuse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GetPromptOptions ¶
type GetPromptOptions struct {
// Version specifies which version of the prompt to fetch.
// If not set, fetches by label (defaults to "production").
Version *int
// Label specifies which label to fetch (e.g., "production", "staging").
// If not set and Version is not set, defaults to "production".
Label *string
// FallbackPrompt is returned if the prompt cannot be fetched from the API.
// This provides guaranteed availability even during network issues.
FallbackPrompt *model.Prompt
// CacheTTL overrides the default cache TTL for this specific request.
// If not set, uses the client's default cache TTL.
CacheTTL *time.Duration
// FetchTimeout sets the timeout for the API request.
// If not set, uses the context's deadline.
FetchTimeout *time.Duration
// ForceRefresh bypasses the cache and fetches directly from the API.
ForceRefresh bool
}
GetPromptOptions contains options for fetching a prompt
type Langfuse ¶
type Langfuse struct {
// contains filtered or unexported fields
}
func New ¶
New constructs a Langfuse client. The TracerProvider is built lazily on the first observation call so that misconfiguration (e.g. missing keys in tests) surfaces only when the SDK is actually used.
func (*Langfuse) ClearPromptCache ¶
func (l *Langfuse) ClearPromptCache()
ClearPromptCache clears all cached prompts.
func (*Langfuse) DeleteScore ¶ added in v1.2.0
DeleteScore deletes a score by its ID.
func (*Langfuse) Flush ¶
Flush blocks until queued spans have been exported. Equivalent to OTel's ForceFlush on the underlying TracerProvider.
func (*Langfuse) Generation ¶
func (l *Langfuse) Generation(g *model.Generation, parentID *string) (*model.Generation, error)
Generation opens a generation span. If g.EndTime is set at call time, the span is started and ended in one shot; otherwise it stays open until GenerationEnd is called.
func (*Langfuse) GenerationEnd ¶
func (l *Langfuse) GenerationEnd(g *model.Generation) (*model.Generation, error)
GenerationEnd closes a generation span previously opened by Generation.
func (*Langfuse) GetPrompt ¶
func (l *Langfuse) GetPrompt(ctx context.Context, name string, opts *GetPromptOptions) (*model.Prompt, error)
GetPrompt fetches a prompt by name. By default, fetches the "production" labeled version. Uses caching to minimize API calls.
func (*Langfuse) Score ¶
Score creates a score via Langfuse's REST API. Scores are not part of the OTel ingestion path.
func (*Langfuse) Shutdown ¶ added in v1.2.3
Shutdown flushes and tears down the OTel TracerProvider. Call on process exit. After Shutdown, the Langfuse client must not be reused.
func (*Langfuse) Trace ¶
Trace opens a root span representing a Langfuse trace. The returned trace's ID is the caller-supplied ID (or a fresh UUID) and is used as the key for later observations and TraceEnd.
func (*Langfuse) TraceEnd ¶ added in v1.2.3
TraceEnd closes the root span for traceID. Calling it ensures the trace's duration reflects real work rather than the SDK's process lifetime.
func (*Langfuse) WithFlushInterval ¶
WithFlushInterval is retained for API compatibility. The OTel batcher uses its own scheduling; this is a no-op.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
cmd/ingestion
command
|
|
|
cmd/prompt
command
|
|
|
internal
|
|
|
pkg/api
Package api is a thin REST client for the Langfuse endpoints that are not covered by OTLP ingestion: prompt management and scores.
|
Package api is a thin REST client for the Langfuse endpoints that are not covered by OTLP ingestion: prompt management and scores. |
|
pkg/otel
Package otel wires up an isolated OpenTelemetry TracerProvider that exports spans to Langfuse via OTLP HTTP.
|
Package otel wires up an isolated OpenTelemetry TracerProvider that exports spans to Langfuse via OTLP HTTP. |