Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBatchFailed = errors.New("langfuse: batch ingestion failed")
Functions ¶
This section is empty.
Types ¶
type BatchError ¶
type BatchError struct {
Errors []api.IngestionError `json:"errors"`
}
func (*BatchError) Error ¶
func (e *BatchError) Error() string
func (*BatchError) Unwrap ¶
func (e *BatchError) Unwrap() error
Unwrap allows the error to be checked with errors.Is without type assertion
type Client ¶
Client provides ergonomic methods for ingesting observations and other APIs.
func New ¶
func New(opts *ClientOptions) (*Client, error)
New creates a client from code-generated API client implementation.
Note: the `API` field takes care of Basic Auth.
func (*Client) Batch ¶
func (c *Client) Batch(ctx context.Context, events []Ingestible) error
Batch submits a series of ingestibles to the upstream API.
func (*Client) Flush ¶
Flush will batch all ingestibles remaining in the client's buffer.
You would typically `defer client.Flush()`.
func (*Client) Ingest ¶
func (c *Client) Ingest(event Ingestible)
Ingest adds an ingestible to the client's buffer, after populating it.
func (*Client) Populate ¶
func (c *Client) Populate(event Ingestible)
Populate populates the traces and spans with the client.
You will typically use this on spans after unmarshalling them from the database metadata column, or for inputs that didn't originate from the client directly.
type ClientOptions ¶
type ClientOptions struct {
Host string
PrivateKey string
PublicKey string
HTTPClient *http.Client
}
ClientOptions are the determining the API line for this package.
The client will inherit the provided HTTP client, or otherwise use sane defaults for transport, dialer, and timeouts. If you wish to control these variables, you absolutely should provide your own client.
type Event ¶
type Event struct {
Id string `json:"id"`
TraceId string `json:"traceId,omitempty"`
Name string `json:"name,omitempty"`
StartTime time.Time `json:"startTime"`
Metadata any `json:"metadata,omitempty"`
Input any `json:"input,omitempty"`
Output any `json:"output,omitempty"`
Level string `json:"level,omitempty"`
StatusMessage string `json:"statusMessage,omitempty"`
ParentObservationId string `json:"parentObservationId,omitempty"`
Version string `json:"version,omitempty"`
Environment string `json:"environment,omitempty"`
}
type EventType ¶
type EventType string
EventType corresponds to various events supported by Langfuse.
Events are distinct from observations: for example, a single observation may appear as multiple events: first, when it is created, and then when it is updated.
const ( TRACE_CREATE EventType = "trace-create" SCORE_CREATE EventType = "score-create" SPAN_CREATE EventType = "span-create" SPAN_UPDATE EventType = "span-update" GENERATION_CREATE EventType = "generation-create" GENERATION_UPDATE EventType = "generation-update" EVENT_CREATE EventType = "event-create" SDK_LOG EventType = "sdk-log" OBSERVATION_CREATE EventType = "observation-create" OBSERVATION_UPDATE EventType = "observation-update" )
type Generation ¶
type Generation struct {
Id string `json:"id"`
TraceId string `json:"traceId,omitempty"`
Name string `json:"name,omitempty"`
StartedAt time.Time `json:"startTime"`
EndedAt *time.Time `json:"endTime,omitempty"`
CompletionAt *time.Time `json:"completionStartTime,omitempty"`
Model string `json:"model,omitempty"`
ModelParameters map[string]any `json:"modelParameters,omitempty"`
Usage any `json:"usage,omitempty"`
UsageDetails any `json:"usageDetails,omitempty"`
CostDetails map[string]float64 `json:"costDetails,omitempty"`
PromptName string `json:"promptName,omitempty"`
PromptVersion *int `json:"promptVersion,omitempty"`
Metadata any `json:"metadata,omitempty"`
Input any `json:"input,omitempty"`
Output any `json:"output,omitempty"`
Level string `json:"level,omitempty"`
StatusMessage string `json:"statusMessage,omitempty"`
ParentObservationId string `json:"parentObservationId,omitempty"`
Version string `json:"version,omitempty"`
Environment string `json:"environment,omitempty"`
}
func (*Generation) End ¶
func (g *Generation) End()
func (*Generation) EventId ¶
func (g *Generation) EventId() string
func (*Generation) EventTime ¶
func (g *Generation) EventTime() time.Time
func (*Generation) EventType ¶
func (g *Generation) EventType() EventType
type Ingestible ¶
Ingestible represents an observation, or update thereof, that Langfuse will ingest using Batched ingestion API. The schema is a bit awkward; to make it more ergonomic, the observation types (Span, Generation, Event) themselves will determine whether they are created or updated.
For example, calling End() on a span will set its EndedAt time, and ingest an update. Therefore, if defer sequence is client.Flush, span.End, then the span will first be ingested as not having endTime, then again as an update with endTime set, and finally flushed.
https://api.reference.langfuse.com/#tag/ingestion/POST/api/public/ingestion
type Span ¶
type Span struct {
Id string `json:"id"`
TraceId string `json:"traceId,omitempty"`
Name string `json:"name,omitempty"`
StartedAt time.Time `json:"startTime"`
EndedAt *time.Time `json:"endTime,omitempty"`
Metadata any `json:"metadata,omitempty"`
Input any `json:"input,omitempty"`
Output any `json:"output,omitempty"`
Level string `json:"level,omitempty"`
StatusMessage string `json:"statusMessage,omitempty"`
ParentObservationId string `json:"parentObservationId,omitempty"`
Version string `json:"version,omitempty"`
Environment string `json:"environment,omitempty"`
// contains filtered or unexported fields
}
func (*Span) Generation ¶
func (s *Span) Generation(g *Generation) *Generation
type Trace ¶
type Trace struct {
Id string `json:"id"`
Name string `json:"name"`
SessionId string `json:"sessionId,omitempty"`
UserId string `json:"userId,omitempty"`
Environment string `json:"environment,omitempty"`
Release string `json:"release,omitempty"`
Version string `json:"version,omitempty"`
Tags []string `json:"tags,omitempty"`
Input any `json:"input,omitempty"`
Metadata any `json:"metadata,omitempty"`
Output any `json:"output,omitempty"`
Public bool `json:"public,omitempty"`
Timestamp time.Time `json:"timestamp"`
// contains filtered or unexported fields
}