Documentation
¶
Index ¶
- func SetTrace(ctx context.Context, opts ...TraceOption) context.Context
- type CallbackHandler
- 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, err 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) UpdateTraceOutput(ctx context.Context, traceID string, output string)
- type Config
- 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 WithName(name string) 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 ¶
Types ¶
type CallbackHandler ¶
type CallbackHandler struct {
// contains filtered or unexported fields
}
func NewLangfuseHandler ¶
func NewLangfuseHandler(cfg *Config) (handler *CallbackHandler, flusher func())
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) UpdateTraceOutput ¶
func (c *CallbackHandler) UpdateTraceOutput(ctx context.Context, traceID string, output string)
UpdateTraceOutput pushes final trace output to Langfuse (via ACL EndTrace). ctx is reserved for future cancellation / deadline propagation; callers may pass context.Background() for now.
type Config ¶
type Config struct {
// Host is the Langfuse server URL (Required)
// Example: "https://cloud.langfuse.com"
Host string
// PublicKey is the public key for authentication (Required)
// Example: "pk-lf-..."
PublicKey string
// SecretKey is the secret key for authentication (Required)
// Example: "sk-lf-..."
SecretKey string
// Threads is the number of concurrent workers for processing events (Optional)
// Default: 1
// Example: 5
Threads int
// Timeout is the HTTP request timeout (Optional)
// Default: no timeout
// Example: 30 * time.Second
Timeout time.Duration
// MaxTaskQueueSize is the maximum number of events to buffer (Optional)
// Default: 100
// Example: 1000
MaxTaskQueueSize int
// MaxEventSizeBytes is the maximum size of an event before large fields are truncated (Optional)
// Default: 1_000_000
// Example: 2_000_000
MaxEventSizeBytes int
// FlushAt is the number of events to batch before sending (Optional)
// Default: 15
// Example: 50
FlushAt int
// FlushInterval is how often to flush events automatically (Optional)
// Default: 500 * time.MilliSecond
// Example: 10 * time.Second
FlushInterval time.Duration
// SampleRate is the percentage of events to send (Optional)
// Default: 1.0 (100%)
// Example: 0.5 (50%)
SampleRate float64
// LogMessage is the message to log when events exceed the limit length(1 000 000) (Optional)
// Default: ""
// Example: "langfuse event:"
LogMessage string
// MaskFunc is a function to mask sensitive data before sending (Optional)
// Default: nil
// Example: func(s string) string { return strings.ReplaceAll(s, "secret", "***") }
MaskFunc func(string) string
// MaxRetry is the maximum number of retry attempts for failed requests (Optional)
// Default: 3
// Example: 5
MaxRetry uint64
// Name is the trace name (Optional)
// Default: ""
// Example: "my-app-trace"
Name string
// UserID is the user identifier for the trace (Optional)
// Default: ""
// Example: "user-123"
UserID string
// SessionID is the session identifier for the trace (Optional)
// Default: ""
// Example: "session-456"
SessionID string
// Release is the version or release identifier (Optional)
// Default: ""
// Example: "v1.2.3"
Release string
// Tags are labels attached to the trace (Optional)
// Default: nil
// Example: []string{"production", "feature-x"}
Tags []string
// Public determines if the trace is publicly accessible (Optional)
// Default: false
// Example: true
Public bool
}
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 WithName ¶
func WithName(name string) 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
Click to show internal directories.
Click to hide internal directories.