Documentation
¶
Overview ¶
Package langfuse converts CloudWeGo Eino callbacks into Langfuse-compatible OpenTelemetry spans and exports them over OTLP/HTTP.
Index ¶
- type CallbackHandler
- func (c *CallbackHandler) EndTrace(ctx context.Context, output string)
- func (c *CallbackHandler) Flush(ctx context.Context) error
- func (c *CallbackHandler) Needed(ctx context.Context, info *callbacks.RunInfo, _ callbacks.CallbackTiming) bool
- func (c *CallbackHandler) OnEnd(ctx context.Context, info *callbacks.RunInfo, output callbacks.CallbackOutput) context.Context
- func (c *CallbackHandler) OnEndWithStreamOutput(ctx context.Context, info *callbacks.RunInfo, ...) context.Context
- func (c *CallbackHandler) OnError(ctx context.Context, info *callbacks.RunInfo, callbackErr error) context.Context
- func (c *CallbackHandler) OnStart(ctx context.Context, info *callbacks.RunInfo, input callbacks.CallbackInput) context.Context
- func (c *CallbackHandler) OnStartWithStreamInput(ctx context.Context, info *callbacks.RunInfo, ...) context.Context
- func (c *CallbackHandler) Shutdown(ctx context.Context) error
- func (c *CallbackHandler) StartTrace(ctx context.Context, opts ...TraceOption) context.Context
- type Config
- type ObservationType
- type TraceOption
- func WithEnvironment(environment string) TraceOption
- func WithID(id string) TraceOption
- func WithInput(input string) TraceOption
- func WithMetadata(metadata map[string]string) TraceOption
- func WithMetadataValues(metadata map[string]any) TraceOption
- func WithName(name string) TraceOption
- func WithObservationType(observationType ObservationType) TraceOption
- func WithPublic(public bool) TraceOption
- func WithRelease(release string) TraceOption
- func WithSessionID(sessionID string) TraceOption
- func WithTags(tags ...string) TraceOption
- func WithUserID(userID string) TraceOption
- func WithVersion(version string) TraceOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallbackHandler ¶
type CallbackHandler struct {
// contains filtered or unexported fields
}
CallbackHandler converts Eino callbacks into Langfuse-compatible OTEL spans.
func NewHandler ¶
func NewHandler(ctx context.Context, cfg *Config) (*CallbackHandler, error)
NewHandler creates an Eino callback that exports OTLP/HTTP traces using the Langfuse v4 ingestion path.
func (*CallbackHandler) EndTrace ¶
func (c *CallbackHandler) EndTrace(ctx context.Context, output string)
EndTrace records the final root-observation output and requests the trace to end. The root waits for active Eino child callbacks before it is exported. Calling EndTrace more than once is safe.
func (*CallbackHandler) Flush ¶
func (c *CallbackHandler) Flush(ctx context.Context) error
Flush waits for callback-owned stream collectors and flushes completed spans.
func (*CallbackHandler) Needed ¶
func (c *CallbackHandler) Needed(ctx context.Context, info *callbacks.RunInfo, _ callbacks.CallbackTiming) bool
Needed implements callbacks.TimingChecker. When explicitly enabled, it removes Eino Agent implementation details while preserving named business components and their standard context-based parent relationships.
func (*CallbackHandler) OnEnd ¶
func (c *CallbackHandler) OnEnd(ctx context.Context, info *callbacks.RunInfo, output callbacks.CallbackOutput) context.Context
func (*CallbackHandler) OnEndWithStreamOutput ¶
func (c *CallbackHandler) OnEndWithStreamOutput(ctx context.Context, info *callbacks.RunInfo, output *schema.StreamReader[callbacks.CallbackOutput]) context.Context
func (*CallbackHandler) OnStart ¶
func (c *CallbackHandler) OnStart(ctx context.Context, info *callbacks.RunInfo, input callbacks.CallbackInput) context.Context
func (*CallbackHandler) OnStartWithStreamInput ¶
func (c *CallbackHandler) OnStartWithStreamInput(ctx context.Context, info *callbacks.RunInfo, input *schema.StreamReader[callbacks.CallbackInput]) context.Context
func (*CallbackHandler) Shutdown ¶
func (c *CallbackHandler) Shutdown(ctx context.Context) error
Shutdown completes active root observations, drains stream collectors, and shuts down the callback-owned provider.
func (*CallbackHandler) StartTrace ¶
func (c *CallbackHandler) StartTrace(ctx context.Context, opts ...TraceOption) context.Context
StartTrace creates the application root observation. It is ended explicitly by EndTrace, when ctx is done and all active Eino child callbacks have ended, or when the handler shuts down.
type Config ¶
type Config struct {
// Host accepts a Langfuse base URL, an OTLP base URL ending in
// /api/public/otel, or the full /api/public/otel/v1/traces endpoint.
Host string
PublicKey string
SecretKey string
ServiceName string
Environment string
Release string
Version string
Tags []string
Timeout time.Duration
SampleRate float64
// Name, UserID, and SessionID configure default root trace attributes.
// Prefer the corresponding StartTrace options for each trace.
Name string
UserID string
SessionID string
Public bool
// IncludeProcessResourceAttributes adds OTel process.* attributes such as
// PID, owner, executable path, command arguments, and runtime details. It is
// disabled by default to reduce metadata noise and accidental disclosure.
IncludeProcessResourceAttributes bool
// CollapseAgentInternalSpans suppresses implementation-detail spans emitted
// by Eino agents: the same-name Chain beneath an Agent, the ReAct Graph and
// Init Lambda it owns, and unnamed/default-named Lambda wrappers. It is
// disabled by default so the callback preserves complete framework traces
// unless the caller explicitly opts into a compact hierarchy. Matching
// components outside an Agent and named business Lambdas are always retained.
CollapseAgentInternalSpans bool
MaxQueueSize int
MaxExportBatchSize int
BatchTimeout time.Duration
// DropLogInterval controls how often discarded telemetry is aggregated into
// one warning. Zero uses one minute. A negative value logs each discard
// immediately; export failures are always logged immediately.
DropLogInterval time.Duration
// MaxAttributeValueLength limits each serialized input, output, or metadata
// value. Set a negative value to disable this callback-level limit.
MaxAttributeValueLength int
// MaxSpanAttributeBytes limits the combined keys and values written by this
// callback to one span. Set a negative value to disable the span-level budget.
MaxSpanAttributeBytes int
MaskFunc func(string) string
HTTPClient *http.Client
// ExportDiagnostics adds protobuf and gzip payload sizes, HTTP attempt
// counts, and network-stage timings to the final export failure log. It
// never logs span contents or trace IDs. Collection has a small CPU and
// allocation cost because the first compressed request body is inspected.
ExportDiagnostics bool
// SpanExporter is intended for custom transports and tests. When set, Host
// and API keys are not used to construct an exporter.
SpanExporter sdktrace.SpanExporter
// TracerProvider lets callers supply an existing provider. The callback does
// not shut down a caller-owned provider. Custom trace IDs requested through
// WithID are only guaranteed when the callback creates the provider.
TracerProvider *sdktrace.TracerProvider
}
Config configures the Langfuse OTLP/HTTP callback.
type ObservationType ¶
type ObservationType string
const ( ObservationTypeEvent ObservationType = "event" ObservationTypeSpan ObservationType = "span" ObservationTypeGeneration ObservationType = "generation" ObservationTypeAgent ObservationType = "agent" ObservationTypeTool ObservationType = "tool" ObservationTypeChain ObservationType = "chain" ObservationTypeRetriever ObservationType = "retriever" ObservationTypeEvaluator ObservationType = "evaluator" ObservationTypeEmbedding ObservationType = "embedding" ObservationTypeGuardrail ObservationType = "guardrail" )
type TraceOption ¶
type TraceOption func(*traceOptions)
func WithEnvironment ¶
func WithEnvironment(environment string) TraceOption
func WithID ¶
func WithID(id string) TraceOption
func WithInput ¶
func WithInput(input string) TraceOption
func WithMetadata ¶
func WithMetadata(metadata map[string]string) TraceOption
func WithMetadataValues ¶
func WithMetadataValues(metadata map[string]any) TraceOption
func WithName ¶
func WithName(name string) TraceOption
func WithObservationType ¶
func WithObservationType(observationType ObservationType) TraceOption
func WithPublic ¶
func WithPublic(public bool) TraceOption
func WithRelease ¶
func WithRelease(release string) TraceOption
func WithSessionID ¶
func WithSessionID(sessionID string) TraceOption
func WithTags ¶
func WithTags(tags ...string) TraceOption
func WithUserID ¶
func WithUserID(userID string) TraceOption
func WithVersion ¶
func WithVersion(version string) TraceOption