Documentation
¶
Index ¶
- Constants
- Variables
- func ContextWithClient(ctx context.Context, client *Client) context.Context
- func ContextWithSpan(ctx context.Context, span *Span) context.Context
- func ContextWithTrace(ctx context.Context, trace *Trace) context.Context
- func CurrentSpanID(ctx context.Context) string
- func CurrentTraceID(ctx context.Context) string
- func EndSpan(ctx context.Context, opts ...SpanOption) error
- func EndTrace(ctx context.Context, opts ...TraceOption) error
- func InjectDistributedTraceHeaders(ctx context.Context, req *http.Request)
- func IsNotFound(err error) bool
- func IsRateLimited(err error) bool
- func IsUnauthorized(err error) bool
- func PropagatingHTTPClient() *http.Client
- func SaveConfig(cfg *Config) error
- type APIError
- type Attachment
- func ImageFromBase64(name, base64Data, mimeType string) (*Attachment, error)
- func ImageFromURL(ctx context.Context, name, url string) (*Attachment, error)
- func NewAttachmentFromBytes(name string, data []byte, mimeType string) *Attachment
- func NewAttachmentFromFile(path string) (*Attachment, error)
- func NewAttachmentFromReader(name string, r io.Reader, mimeType string) (*Attachment, error)
- func NewAttachmentFromURL(name string, url string, attachType AttachmentType) *Attachment
- func NewImageAttachment(name string, data []byte, mimeType string) *Attachment
- func NewTextAttachment(name, content string) *Attachment
- type AttachmentExtractor
- type AttachmentOption
- type AttachmentType
- type AttachmentUploader
- type BatchItem
- type Batcher
- type BatcherConfig
- type BatchingClient
- type BufferingStreamHandler
- func (h *BufferingStreamHandler) Accumulator() *StreamAccumulator
- func (h *BufferingStreamHandler) Content() string
- func (h *BufferingStreamHandler) Finalize() error
- func (h *BufferingStreamHandler) HandleChunk(chunk StreamChunk) error
- func (h *BufferingStreamHandler) OnChunk(fn func(chunk StreamChunk) error)
- type Client
- func (c *Client) API() *api.Client
- func (c *Client) Config() *Config
- func (c *Client) ContinueTrace(ctx context.Context, headers DistributedTraceHeaders, spanName string, ...) (context.Context, *Span, error)
- func (c *Client) CreateDataset(ctx context.Context, name string, opts ...DatasetOption) (*Dataset, error)
- func (c *Client) CreateExperiment(ctx context.Context, datasetName string, opts ...ExperimentOption) (*Experiment, error)
- func (c *Client) CreateProject(ctx context.Context, name string, opts ...ProjectOption) (*Project, error)
- func (c *Client) CreatePrompt(ctx context.Context, name string, opts ...PromptOption) (*Prompt, error)
- func (c *Client) DeleteDataset(ctx context.Context, datasetID string) error
- func (c *Client) DeleteExperiment(ctx context.Context, experimentID string) error
- func (c *Client) DeletePrompt(ctx context.Context, promptID string) error
- func (c *Client) GetDataset(ctx context.Context, datasetID string) (*Dataset, error)
- func (c *Client) GetDatasetByName(ctx context.Context, name string) (*Dataset, error)
- func (c *Client) GetExperiment(ctx context.Context, experimentID string) (*Experiment, error)
- func (c *Client) GetPrompt(ctx context.Context, promptID string) (*Prompt, error)
- func (c *Client) GetPromptByName(ctx context.Context, name string, commit string) (*PromptVersion, error)
- func (c *Client) GetTrace(ctx context.Context, traceID string) (*Trace, error)
- func (c *Client) IsTracingEnabled() bool
- func (c *Client) ListDatasets(ctx context.Context, page, size int) ([]*Dataset, error)
- func (c *Client) ListExperiments(ctx context.Context, datasetID string, page, size int) ([]*Experiment, error)
- func (c *Client) ListProjects(ctx context.Context, page, size int) ([]*Project, error)
- func (c *Client) ListPrompts(ctx context.Context, page, size int) ([]*Prompt, error)
- func (c *Client) ListSpans(ctx context.Context, traceID string, page, size int) ([]*SpanInfo, error)
- func (c *Client) ListTraces(ctx context.Context, page, size int) ([]*TraceInfo, error)
- func (c *Client) ProjectName() string
- func (c *Client) SetProjectName(name string)
- func (c *Client) Trace(ctx context.Context, name string, opts ...TraceOption) (*Trace, error)
- type Config
- type Dataset
- func (d *Dataset) Delete(ctx context.Context) error
- func (d *Dataset) Description() string
- func (d *Dataset) GetItems(ctx context.Context, page, size int) ([]DatasetItem, error)
- func (d *Dataset) ID() string
- func (d *Dataset) InsertItem(ctx context.Context, data map[string]any, opts ...DatasetItemOption) error
- func (d *Dataset) InsertItems(ctx context.Context, items []map[string]any, opts ...DatasetItemOption) error
- func (d *Dataset) Name() string
- func (d *Dataset) Tags() []string
- type DatasetItem
- type DatasetItemOption
- type DatasetOption
- type DistributedTraceHeaders
- type Experiment
- func (e *Experiment) Cancel(ctx context.Context) error
- func (e *Experiment) Complete(ctx context.Context) error
- func (e *Experiment) DatasetName() string
- func (e *Experiment) Delete(ctx context.Context) error
- func (e *Experiment) ID() string
- func (e *Experiment) LogItem(ctx context.Context, datasetItemID, traceID string, ...) error
- func (e *Experiment) Metadata() map[string]any
- func (e *Experiment) Name() string
- type ExperimentItem
- type ExperimentItemOption
- type ExperimentOption
- type ExperimentStatus
- type ExperimentType
- type FeedbackBatchItem
- type LocalRecording
- func (r *LocalRecording) AddFeedback(entityID string, feedback RecordedFeedback)
- func (r *LocalRecording) AddSpan(span *RecordedSpan)
- func (r *LocalRecording) AddTrace(trace *RecordedTrace)
- func (r *LocalRecording) Clear()
- func (r *LocalRecording) GetSpan(id string) *RecordedSpan
- func (r *LocalRecording) GetTrace(id string) *RecordedTrace
- func (r *LocalRecording) SpanCount() int
- func (r *LocalRecording) Spans() []*RecordedSpan
- func (r *LocalRecording) TraceCount() int
- func (r *LocalRecording) Traces() []*RecordedTrace
- type Option
- func WithAPIKey(apiKey string) Option
- func WithConfig(config *Config) Option
- func WithHTTPClient(client *http.Client) Option
- func WithProjectName(projectName string) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTracingDisabled(disabled bool) Option
- func WithURL(url string) Option
- func WithWorkspace(workspace string) Option
- type Project
- type ProjectOption
- type Prompt
- func (p *Prompt) CreateVersion(ctx context.Context, template string, opts ...PromptVersionOption) (*PromptVersion, error)
- func (p *Prompt) Delete(ctx context.Context) error
- func (p *Prompt) Description() string
- func (p *Prompt) GetVersions(ctx context.Context, page, size int) ([]*PromptVersion, error)
- func (p *Prompt) ID() string
- func (p *Prompt) Name() string
- func (p *Prompt) Tags() []string
- func (p *Prompt) Template() string
- type PromptOption
- func WithPromptChangeDescription(changeDescription string) PromptOption
- func WithPromptDescription(description string) PromptOption
- func WithPromptTags(tags ...string) PromptOption
- func WithPromptTemplate(template string) PromptOption
- func WithPromptTemplateStructure(structure PromptTemplateStructure) PromptOption
- func WithPromptType(promptType PromptType) PromptOption
- type PromptTemplateStructure
- type PromptType
- type PromptVersion
- func (v *PromptVersion) ChangeDescription() string
- func (v *PromptVersion) Commit() string
- func (v *PromptVersion) ExtractVariables() []string
- func (v *PromptVersion) ID() string
- func (v *PromptVersion) PromptID() string
- func (v *PromptVersion) Render(variables map[string]string) string
- func (v *PromptVersion) RenderWithDefault(variables map[string]string, defaultValue string) string
- func (v *PromptVersion) Tags() []string
- func (v *PromptVersion) Template() string
- type PromptVersionOption
- type PropagatingRoundTripper
- type RecordedFeedback
- type RecordedSpan
- type RecordedTrace
- type RecordingClient
- type RecordingSpan
- func (s *RecordingSpan) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error
- func (s *RecordingSpan) End(ctx context.Context, opts ...SpanOption) error
- func (s *RecordingSpan) ID() string
- func (s *RecordingSpan) Name() string
- func (s *RecordingSpan) Span(ctx context.Context, name string, opts ...SpanOption) (*RecordingSpan, error)
- func (s *RecordingSpan) TraceID() string
- type RecordingTrace
- func (t *RecordingTrace) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error
- func (t *RecordingTrace) End(ctx context.Context, opts ...TraceOption) error
- func (t *RecordingTrace) ID() string
- func (t *RecordingTrace) Name() string
- func (t *RecordingTrace) Span(ctx context.Context, name string, opts ...SpanOption) (*RecordingSpan, error)
- type Span
- func (s *Span) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error
- func (s *Span) End(ctx context.Context, opts ...SpanOption) error
- func (s *Span) EndTime() *time.Time
- func (s *Span) ID() string
- func (s *Span) Name() string
- func (s *Span) ParentSpanID() string
- func (s *Span) SetUsage(usage map[string]int)
- func (s *Span) Span(ctx context.Context, name string, opts ...SpanOption) (*Span, error)
- func (s *Span) StartTime() time.Time
- func (s *Span) TraceID() string
- func (s *Span) Type() string
- func (s *Span) Update(ctx context.Context, opts ...SpanOption) error
- type SpanBatchItem
- type SpanInfo
- type SpanOption
- func WithSpanInput(input any) SpanOption
- func WithSpanMetadata(metadata map[string]any) SpanOption
- func WithSpanModel(model string) SpanOption
- func WithSpanOutput(output any) SpanOption
- func WithSpanProvider(provider string) SpanOption
- func WithSpanTags(tags ...string) SpanOption
- func WithSpanType(spanType string) SpanOption
- type StreamAccumulator
- func (a *StreamAccumulator) AddChunk(chunk StreamChunk)
- func (a *StreamAccumulator) ChunkCount() int
- func (a *StreamAccumulator) Content() string
- func (a *StreamAccumulator) Duration() time.Duration
- func (a *StreamAccumulator) FinishReason() string
- func (a *StreamAccumulator) Metadata() map[string]any
- func (a *StreamAccumulator) TimeToFirstChunk(streamStart time.Time) time.Duration
- func (a *StreamAccumulator) ToOutput() map[string]any
- func (a *StreamAccumulator) TotalTokens() int
- type StreamChunk
- type StreamChunkOption
- type StreamHandler
- type StreamingSpan
- func (s *StreamingSpan) Accumulator() *StreamAccumulator
- func (s *StreamingSpan) AddChunk(content string, opts ...StreamChunkOption)
- func (s *StreamingSpan) End(ctx context.Context, opts ...SpanOption) error
- func (s *StreamingSpan) ID() string
- func (s *StreamingSpan) OnChunk(fn func(chunk StreamChunk))
- func (s *StreamingSpan) Span() *Span
- func (s *StreamingSpan) TraceID() string
- type Trace
- func (t *Trace) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error
- func (t *Trace) End(ctx context.Context, opts ...TraceOption) error
- func (t *Trace) EndTime() *time.Time
- func (t *Trace) ID() string
- func (t *Trace) Name() string
- func (t *Trace) ProjectName() string
- func (t *Trace) Span(ctx context.Context, name string, opts ...SpanOption) (*Span, error)
- func (t *Trace) StartTime() time.Time
- func (t *Trace) Update(ctx context.Context, opts ...TraceOption) error
- type TraceBatchItem
- type TraceInfo
- type TraceOption
- func WithTraceInput(input any) TraceOption
- func WithTraceMetadata(metadata map[string]any) TraceOption
- func WithTraceOutput(output any) TraceOption
- func WithTraceProject(projectName string) TraceOption
- func WithTraceTags(tags ...string) TraceOption
- func WithTraceThreadID(threadID string) TraceOption
- type TracingStreamHandler
Constants ¶
const ( // DefaultCloudURL is the default URL for Opik Cloud DefaultCloudURL = "https://www.comet.com/opik/api" // DefaultLocalURL is the default URL for local Opik server DefaultLocalURL = "http://localhost:5173/api" // DefaultProjectName is the default project name DefaultProjectName = "Default Project" // DefaultWorkspace is the default workspace name DefaultWorkspace = "default" // DefaultConfigFile is the default config file path DefaultConfigFile = "~/.opik.config" )
const ( EnvURLOverride = "OPIK_URL_OVERRIDE" EnvAPIKey = "OPIK_API_KEY" //nolint:gosec // G101: This is an environment variable name, not a credential EnvWorkspace = "OPIK_WORKSPACE" EnvProjectName = "OPIK_PROJECT_NAME" EnvTraceDisable = "OPIK_TRACK_DISABLE" )
Environment variable names
const ( HeaderTraceID = "X-Opik-Trace-ID" HeaderParentSpanID = "X-Opik-Parent-Span-ID" )
Header names for distributed tracing.
const SpanTypeGeneral = "general"
SpanTypeGeneral is the span type for general operations.
const SpanTypeGuardrail = "guardrail"
SpanTypeGuardrail is the span type for guardrail checks.
const SpanTypeLLM = "llm"
SpanTypeLLM is the span type for LLM calls.
const SpanTypeTool = "tool"
SpanTypeTool is the span type for tool calls.
const Version = "0.1.0"
Version is the SDK version.
Variables ¶
var ( // ErrMissingURL is returned when the API URL is not configured. ErrMissingURL = errors.New("opik: missing API URL") // ErrMissingAPIKey is returned when the API key is required but not provided. ErrMissingAPIKey = errors.New("opik: missing API key for Opik Cloud") // ErrMissingWorkspace is returned when the workspace is required but not provided. ErrMissingWorkspace = errors.New("opik: missing workspace for Opik Cloud") // ErrTracingDisabled is returned when tracing is disabled. ErrTracingDisabled = errors.New("opik: tracing is disabled") // ErrTraceNotFound is returned when a trace cannot be found. ErrTraceNotFound = errors.New("opik: trace not found") // ErrSpanNotFound is returned when a span cannot be found. ErrSpanNotFound = errors.New("opik: span not found") // ErrDatasetNotFound is returned when a dataset cannot be found. ErrDatasetNotFound = errors.New("opik: dataset not found") // ErrExperimentNotFound is returned when an experiment cannot be found. ErrExperimentNotFound = errors.New("opik: experiment not found") // ErrPromptNotFound is returned when a prompt cannot be found. ErrPromptNotFound = errors.New("opik: prompt not found") // ErrInvalidInput is returned when input validation fails. ErrInvalidInput = errors.New("opik: invalid input") // ErrNoActiveTrace is returned when there is no active trace in context. ErrNoActiveTrace = errors.New("opik: no active trace in context") // ErrNoActiveSpan is returned when there is no active span in context. ErrNoActiveSpan = errors.New("opik: no active span in context") )
Sentinel errors for the Opik SDK.
Functions ¶
func ContextWithClient ¶
ContextWithClient returns a new context with the client attached.
func ContextWithSpan ¶
ContextWithSpan returns a new context with the span attached.
func ContextWithTrace ¶
ContextWithTrace returns a new context with the trace attached.
func CurrentSpanID ¶
CurrentSpanID returns the current span ID from the context, or empty string if none.
func CurrentTraceID ¶
CurrentTraceID returns the current trace ID from the context, or empty string if none.
func EndSpan ¶
func EndSpan(ctx context.Context, opts ...SpanOption) error
EndSpan ends the current span in the context.
func EndTrace ¶
func EndTrace(ctx context.Context, opts ...TraceOption) error
EndTrace ends the current trace in the context.
func InjectDistributedTraceHeaders ¶
InjectDistributedTraceHeaders adds trace context headers to an HTTP request.
func IsNotFound ¶
IsNotFound returns true if the error indicates a resource was not found.
func IsRateLimited ¶
IsRateLimited returns true if the error indicates rate limiting.
func IsUnauthorized ¶
IsUnauthorized returns true if the error indicates an authentication failure.
func PropagatingHTTPClient ¶
PropagatingHTTPClient returns an http.Client that automatically propagates distributed trace headers to all outgoing requests.
func SaveConfig ¶
SaveConfig saves the configuration to the config file.
Types ¶
type Attachment ¶
type Attachment struct {
// Name is the display name of the attachment.
Name string
// Type is the attachment type (image, audio, etc.).
Type AttachmentType
// MimeType is the MIME type of the attachment.
MimeType string
// Data is the raw attachment data.
Data []byte
// URL is an optional URL for externally hosted attachments.
URL string
// Base64 is the base64-encoded data (for embedding).
Base64 string
}
Attachment represents a file attachment for a trace or span.
func ImageFromBase64 ¶
func ImageFromBase64(name, base64Data, mimeType string) (*Attachment, error)
ImageFromBase64 creates an Attachment from a base64 string.
func ImageFromURL ¶
func ImageFromURL(ctx context.Context, name, url string) (*Attachment, error)
ImageFromURL fetches and creates an Attachment from a URL.
func NewAttachmentFromBytes ¶
func NewAttachmentFromBytes(name string, data []byte, mimeType string) *Attachment
NewAttachmentFromBytes creates an attachment from raw bytes.
func NewAttachmentFromFile ¶
func NewAttachmentFromFile(path string) (*Attachment, error)
NewAttachmentFromFile creates an attachment from a file path.
func NewAttachmentFromReader ¶
NewAttachmentFromReader creates an attachment from an io.Reader.
func NewAttachmentFromURL ¶
func NewAttachmentFromURL(name string, url string, attachType AttachmentType) *Attachment
NewAttachmentFromURL creates an attachment from a URL.
func NewImageAttachment ¶
func NewImageAttachment(name string, data []byte, mimeType string) *Attachment
NewImageAttachment creates an image attachment from bytes.
func NewTextAttachment ¶
func NewTextAttachment(name, content string) *Attachment
NewTextAttachment creates a text attachment.
func (*Attachment) IsEmbeddable ¶
func (a *Attachment) IsEmbeddable(maxSize int) bool
IsEmbeddable returns true if the attachment is small enough to embed inline.
func (*Attachment) Size ¶
func (a *Attachment) Size() int
Size returns the size of the attachment in bytes.
func (*Attachment) ToBase64 ¶
func (a *Attachment) ToBase64() string
ToBase64 returns the base64-encoded attachment data.
func (*Attachment) ToDataURL ¶
func (a *Attachment) ToDataURL() string
ToDataURL returns a data URL for the attachment.
type AttachmentExtractor ¶
type AttachmentExtractor struct {
// contains filtered or unexported fields
}
AttachmentExtractor extracts attachments from LLM responses.
func NewAttachmentExtractor ¶
func NewAttachmentExtractor() *AttachmentExtractor
NewAttachmentExtractor creates a new attachment extractor.
func (*AttachmentExtractor) Extract ¶
func (e *AttachmentExtractor) Extract(content any) []*Attachment
Extract extracts attachments from content.
func (*AttachmentExtractor) SetEnabled ¶
func (e *AttachmentExtractor) SetEnabled(enabled bool)
SetEnabled enables or disables attachment extraction.
type AttachmentOption ¶
type AttachmentOption func(*attachmentOptions)
AttachmentOption is a functional option for attachments.
func WithAttachment ¶
func WithAttachment(attachment *Attachment) AttachmentOption
WithAttachment adds an attachment.
func WithFileAttachment ¶
func WithFileAttachment(path string) AttachmentOption
WithFileAttachment adds a file attachment.
func WithImageAttachment ¶
func WithImageAttachment(name string, data []byte) AttachmentOption
WithImageAttachment adds an image attachment.
func WithTextAttachment ¶
func WithTextAttachment(name, content string) AttachmentOption
WithTextAttachment adds a text attachment.
type AttachmentType ¶
type AttachmentType string
AttachmentType represents the type of attachment.
const ( AttachmentTypeImage AttachmentType = "image" AttachmentTypeAudio AttachmentType = "audio" AttachmentTypeVideo AttachmentType = "video" AttachmentTypeDocument AttachmentType = "document" AttachmentTypeText AttachmentType = "text" AttachmentTypeOther AttachmentType = "other" )
type AttachmentUploader ¶
type AttachmentUploader struct {
// contains filtered or unexported fields
}
AttachmentUploader handles uploading attachments to storage.
func NewAttachmentUploader ¶
func NewAttachmentUploader(client *Client) *AttachmentUploader
NewAttachmentUploader creates a new attachment uploader.
func (*AttachmentUploader) SetMaxEmbedSize ¶
func (u *AttachmentUploader) SetMaxEmbedSize(size int)
SetMaxEmbedSize sets the maximum size for inline embedding.
func (*AttachmentUploader) Upload ¶
func (u *AttachmentUploader) Upload(ctx context.Context, attachment *Attachment) (string, error)
Upload uploads an attachment and returns the URL or embedded data.
func (*AttachmentUploader) UploadMultiple ¶
func (u *AttachmentUploader) UploadMultiple(ctx context.Context, attachments []*Attachment) ([]string, error)
UploadMultiple uploads multiple attachments.
type BatchItem ¶
type BatchItem interface {
// Type returns the type of batch item (e.g., "trace", "span", "feedback").
Type() string
}
BatchItem represents an item to be batched.
type Batcher ¶
type Batcher struct {
// contains filtered or unexported fields
}
Batcher batches operations for efficient API calls.
func NewBatcher ¶
func NewBatcher(client *Client, config BatcherConfig) *Batcher
NewBatcher creates a new batcher with the given configuration.
type BatcherConfig ¶
type BatcherConfig struct {
// MaxBatchSize is the maximum number of items to batch before flushing.
MaxBatchSize int
// FlushInterval is the maximum time to wait before flushing a batch.
FlushInterval time.Duration
// MaxRetries is the maximum number of retries for failed batches.
MaxRetries int
// RetryDelay is the initial delay between retries (doubles each retry).
RetryDelay time.Duration
// Workers is the number of background workers for processing batches.
Workers int
}
BatcherConfig configures the message batcher.
func DefaultBatcherConfig ¶
func DefaultBatcherConfig() BatcherConfig
DefaultBatcherConfig returns the default batcher configuration.
type BatchingClient ¶
type BatchingClient struct {
*Client
// contains filtered or unexported fields
}
BatchingClient wraps a Client with batching support.
func NewBatchingClient ¶
func NewBatchingClient(opts ...Option) (*BatchingClient, error)
NewBatchingClient creates a new client with batching enabled.
func NewBatchingClientWithConfig ¶
func NewBatchingClientWithConfig(config BatcherConfig, opts ...Option) (*BatchingClient, error)
NewBatchingClientWithConfig creates a new client with custom batching config.
func (*BatchingClient) AddFeedbackAsync ¶
func (c *BatchingClient) AddFeedbackAsync(entityType, entityID, name string, value float64, reason string)
AddFeedbackAsync adds a feedback score asynchronously via batching.
type BufferingStreamHandler ¶
type BufferingStreamHandler struct {
// contains filtered or unexported fields
}
BufferingStreamHandler buffers chunks and calls a callback with complete content.
func NewBufferingStreamHandler ¶
func NewBufferingStreamHandler(onComplete func(content string) error) *BufferingStreamHandler
NewBufferingStreamHandler creates a buffering handler.
func (*BufferingStreamHandler) Accumulator ¶
func (h *BufferingStreamHandler) Accumulator() *StreamAccumulator
Accumulator returns the stream accumulator.
func (*BufferingStreamHandler) Content ¶
func (h *BufferingStreamHandler) Content() string
Content returns the current buffered content.
func (*BufferingStreamHandler) Finalize ¶
func (h *BufferingStreamHandler) Finalize() error
Finalize calls the completion callback with buffered content.
func (*BufferingStreamHandler) HandleChunk ¶
func (h *BufferingStreamHandler) HandleChunk(chunk StreamChunk) error
HandleChunk adds a chunk to the buffer.
func (*BufferingStreamHandler) OnChunk ¶
func (h *BufferingStreamHandler) OnChunk(fn func(chunk StreamChunk) error)
OnChunk sets a callback for each chunk.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main Opik client for interacting with the Opik API.
func ClientFromContext ¶
ClientFromContext returns the client from the context, or nil if none.
func (*Client) ContinueTrace ¶
func (c *Client) ContinueTrace(ctx context.Context, headers DistributedTraceHeaders, spanName string, opts ...SpanOption) (context.Context, *Span, error)
ContinueTrace creates a new span that continues from distributed trace headers. This is used when receiving a request from another service that has trace context.
func (*Client) CreateDataset ¶
func (c *Client) CreateDataset(ctx context.Context, name string, opts ...DatasetOption) (*Dataset, error)
CreateDataset creates a new dataset.
func (*Client) CreateExperiment ¶
func (c *Client) CreateExperiment(ctx context.Context, datasetName string, opts ...ExperimentOption) (*Experiment, error)
CreateExperiment creates a new experiment for a dataset.
func (*Client) CreateProject ¶
func (c *Client) CreateProject(ctx context.Context, name string, opts ...ProjectOption) (*Project, error)
CreateProject creates a new project.
func (*Client) CreatePrompt ¶
func (c *Client) CreatePrompt(ctx context.Context, name string, opts ...PromptOption) (*Prompt, error)
CreatePrompt creates a new prompt.
func (*Client) DeleteDataset ¶
DeleteDataset deletes a dataset by ID.
func (*Client) DeleteExperiment ¶
DeleteExperiment deletes an experiment by ID.
func (*Client) DeletePrompt ¶
DeletePrompt deletes a prompt by ID.
func (*Client) GetDataset ¶
GetDataset retrieves a dataset by ID.
func (*Client) GetDatasetByName ¶
GetDatasetByName retrieves a dataset by name.
func (*Client) GetExperiment ¶
GetExperiment retrieves an experiment by ID.
func (*Client) GetPromptByName ¶
func (c *Client) GetPromptByName(ctx context.Context, name string, commit string) (*PromptVersion, error)
GetPromptByName retrieves a prompt version by name and optional commit.
func (*Client) IsTracingEnabled ¶
IsTracingEnabled returns true if tracing is enabled.
func (*Client) ListDatasets ¶
ListDatasets lists all datasets.
func (*Client) ListExperiments ¶
func (c *Client) ListExperiments(ctx context.Context, datasetID string, page, size int) ([]*Experiment, error)
ListExperiments lists experiments for a dataset.
func (*Client) ListProjects ¶
ListProjects lists all projects.
func (*Client) ListPrompts ¶
ListPrompts lists all prompts.
func (*Client) ListSpans ¶
func (c *Client) ListSpans(ctx context.Context, traceID string, page, size int) ([]*SpanInfo, error)
ListSpans lists spans for a specific trace.
func (*Client) ListTraces ¶
ListTraces lists recent traces.
func (*Client) ProjectName ¶
ProjectName returns the default project name.
func (*Client) SetProjectName ¶
SetProjectName sets the default project name.
type Config ¶
type Config struct {
// URL is the Opik API endpoint URL.
// Defaults to DefaultCloudURL if APIKey is set, otherwise DefaultLocalURL.
URL string
// APIKey is the API key for authentication with Opik Cloud.
// Not required for local/self-hosted instances.
APIKey string
// Workspace is the workspace name for Opik Cloud.
// Required for Opik Cloud, ignored for local instances.
Workspace string
// ProjectName is the default project name for traces.
ProjectName string
// TracingDisabled disables tracing globally when set to true.
TracingDisabled bool
// CheckTLSCertificate enables TLS certificate verification.
// Defaults to true.
CheckTLSCertificate bool
}
Config holds the configuration for the Opik client.
func LoadConfig ¶
func LoadConfig() *Config
LoadConfig loads configuration from environment variables and config file. Priority order (highest to lowest): 1. Explicitly set values (via options) 2. Environment variables 3. Config file (~/.opik.config) 4. Default values
type Dataset ¶
type Dataset struct {
// contains filtered or unexported fields
}
Dataset represents a dataset in Opik for storing test data.
func (*Dataset) Description ¶
Description returns the dataset description.
func (*Dataset) InsertItem ¶
func (d *Dataset) InsertItem(ctx context.Context, data map[string]any, opts ...DatasetItemOption) error
InsertItem inserts a single item into the dataset.
func (*Dataset) InsertItems ¶
func (d *Dataset) InsertItems(ctx context.Context, items []map[string]any, opts ...DatasetItemOption) error
InsertItems inserts multiple items into the dataset.
type DatasetItem ¶
type DatasetItem struct {
ID string
TraceID string
SpanID string
Data map[string]any
Tags []string
}
DatasetItem represents an item in a dataset.
type DatasetItemOption ¶
type DatasetItemOption func(*datasetItemOptions)
DatasetItemOption is a functional option for configuring a DatasetItem.
func WithDatasetItemTags ¶
func WithDatasetItemTags(tags ...string) DatasetItemOption
WithDatasetItemTags sets the tags for the dataset item.
type DatasetOption ¶
type DatasetOption func(*datasetOptions)
DatasetOption is a functional option for configuring a Dataset.
func WithDatasetDescription ¶
func WithDatasetDescription(description string) DatasetOption
WithDatasetDescription sets the description for the dataset.
func WithDatasetTags ¶
func WithDatasetTags(tags ...string) DatasetOption
WithDatasetTags sets the tags for the dataset.
type DistributedTraceHeaders ¶
type DistributedTraceHeaders struct {
TraceID string `json:"opik_trace_id"`
ParentSpanID string `json:"opik_parent_span_id"`
}
DistributedTraceHeaders contains trace context for cross-service propagation.
func ExtractDistributedTraceHeaders ¶
func ExtractDistributedTraceHeaders(req *http.Request) DistributedTraceHeaders
ExtractDistributedTraceHeaders extracts trace context from HTTP request headers.
func GetDistributedTraceHeaders ¶
func GetDistributedTraceHeaders(ctx context.Context) DistributedTraceHeaders
GetDistributedTraceHeaders returns the current trace context from the context. This can be used to propagate trace context across service boundaries.
type Experiment ¶
type Experiment struct {
// contains filtered or unexported fields
}
Experiment represents an experiment in Opik for evaluating models.
func (*Experiment) Cancel ¶
func (e *Experiment) Cancel(ctx context.Context) error
Cancel marks the experiment as cancelled.
func (*Experiment) Complete ¶
func (e *Experiment) Complete(ctx context.Context) error
Complete marks the experiment as completed.
func (*Experiment) DatasetName ¶
func (e *Experiment) DatasetName() string
DatasetName returns the dataset name.
func (*Experiment) Delete ¶
func (e *Experiment) Delete(ctx context.Context) error
Delete deletes this experiment.
func (*Experiment) LogItem ¶
func (e *Experiment) LogItem(ctx context.Context, datasetItemID, traceID string, opts ...ExperimentItemOption) error
LogItem logs a result for a dataset item in this experiment.
func (*Experiment) Metadata ¶
func (e *Experiment) Metadata() map[string]any
Metadata returns the experiment metadata.
type ExperimentItem ¶
type ExperimentItem struct {
ID string
ExperimentID string
DatasetItemID string
TraceID string
Input any
Output any
}
ExperimentItem represents an item result in an experiment.
type ExperimentItemOption ¶
type ExperimentItemOption func(*experimentItemOptions)
ExperimentItemOption is a functional option for configuring an ExperimentItem.
func WithExperimentItemInput ¶
func WithExperimentItemInput(input any) ExperimentItemOption
WithExperimentItemInput sets the input for the experiment item.
func WithExperimentItemOutput ¶
func WithExperimentItemOutput(output any) ExperimentItemOption
WithExperimentItemOutput sets the output for the experiment item.
type ExperimentOption ¶
type ExperimentOption func(*experimentOptions)
ExperimentOption is a functional option for configuring an Experiment.
func WithExperimentMetadata ¶
func WithExperimentMetadata(metadata map[string]any) ExperimentOption
WithExperimentMetadata sets the metadata for the experiment.
func WithExperimentName ¶
func WithExperimentName(name string) ExperimentOption
WithExperimentName sets the name for the experiment.
func WithExperimentStatus ¶
func WithExperimentStatus(status ExperimentStatus) ExperimentOption
WithExperimentStatus sets the initial status for the experiment.
func WithExperimentType ¶
func WithExperimentType(experimentType ExperimentType) ExperimentOption
WithExperimentType sets the type for the experiment.
type ExperimentStatus ¶
type ExperimentStatus string
ExperimentStatus represents the status of an experiment.
const ( ExperimentStatusRunning ExperimentStatus = "running" ExperimentStatusCompleted ExperimentStatus = "completed" ExperimentStatusCancelled ExperimentStatus = "cancelled" )
type ExperimentType ¶
type ExperimentType string
ExperimentType represents the type of an experiment.
const ( ExperimentTypeRegular ExperimentType = "regular" ExperimentTypeTrial ExperimentType = "trial" ExperimentTypeMiniBatch ExperimentType = "mini-batch" )
type FeedbackBatchItem ¶
type FeedbackBatchItem struct {
EntityType string // "trace" or "span"
EntityID string
Name string
Value float64
Reason string
}
FeedbackBatchItem represents a feedback score to be logged.
func (FeedbackBatchItem) Type ¶
func (f FeedbackBatchItem) Type() string
type LocalRecording ¶
type LocalRecording struct {
// contains filtered or unexported fields
}
LocalRecording captures traces and spans locally without sending to the server.
func NewLocalRecording ¶
func NewLocalRecording() *LocalRecording
NewLocalRecording creates a new local recording storage.
func (*LocalRecording) AddFeedback ¶
func (r *LocalRecording) AddFeedback(entityID string, feedback RecordedFeedback)
AddFeedback adds feedback to the recording.
func (*LocalRecording) AddSpan ¶
func (r *LocalRecording) AddSpan(span *RecordedSpan)
AddSpan adds a span to the recording.
func (*LocalRecording) AddTrace ¶
func (r *LocalRecording) AddTrace(trace *RecordedTrace)
AddTrace adds a trace to the recording.
func (*LocalRecording) GetSpan ¶
func (r *LocalRecording) GetSpan(id string) *RecordedSpan
GetSpan returns a specific span by ID.
func (*LocalRecording) GetTrace ¶
func (r *LocalRecording) GetTrace(id string) *RecordedTrace
GetTrace returns a specific trace by ID.
func (*LocalRecording) SpanCount ¶
func (r *LocalRecording) SpanCount() int
SpanCount returns the number of recorded spans.
func (*LocalRecording) Spans ¶
func (r *LocalRecording) Spans() []*RecordedSpan
Spans returns all recorded spans.
func (*LocalRecording) TraceCount ¶
func (r *LocalRecording) TraceCount() int
TraceCount returns the number of recorded traces.
func (*LocalRecording) Traces ¶
func (r *LocalRecording) Traces() []*RecordedTrace
Traces returns all recorded traces.
type Option ¶
type Option func(*clientOptions)
Option is a functional option for configuring the Client.
func WithAPIKey ¶
WithAPIKey sets the API key for authentication.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
func WithProjectName ¶
WithProjectName sets the default project name.
func WithTimeout ¶
WithTimeout sets the request timeout.
func WithTracingDisabled ¶
WithTracingDisabled disables tracing.
func WithWorkspace ¶
WithWorkspace sets the workspace name.
type Project ¶
type Project struct {
ID string
Name string
Description string
CreatedAt time.Time
LastUpdated time.Time
}
Project represents an Opik project.
type ProjectOption ¶
type ProjectOption func(*projectOptions)
ProjectOption configures a project creation.
func WithProjectDescription ¶
func WithProjectDescription(desc string) ProjectOption
WithProjectDescription sets the project description.
type Prompt ¶
type Prompt struct {
// contains filtered or unexported fields
}
Prompt represents a prompt template in Opik.
func (*Prompt) CreateVersion ¶
func (p *Prompt) CreateVersion(ctx context.Context, template string, opts ...PromptVersionOption) (*PromptVersion, error)
CreateVersion creates a new version of this prompt.
func (*Prompt) Description ¶
Description returns the prompt description.
func (*Prompt) GetVersions ¶
GetVersions retrieves all versions of this prompt.
type PromptOption ¶
type PromptOption func(*promptOptions)
PromptOption is a functional option for configuring a Prompt.
func WithPromptChangeDescription ¶
func WithPromptChangeDescription(changeDescription string) PromptOption
WithPromptChangeDescription sets the change description for the prompt version.
func WithPromptDescription ¶
func WithPromptDescription(description string) PromptOption
WithPromptDescription sets the description for the prompt.
func WithPromptTags ¶
func WithPromptTags(tags ...string) PromptOption
WithPromptTags sets the tags for the prompt.
func WithPromptTemplate ¶
func WithPromptTemplate(template string) PromptOption
WithPromptTemplate sets the template for the prompt.
func WithPromptTemplateStructure ¶
func WithPromptTemplateStructure(structure PromptTemplateStructure) PromptOption
WithPromptTemplateStructure sets the template structure (text or chat).
func WithPromptType ¶
func WithPromptType(promptType PromptType) PromptOption
WithPromptType sets the type for the prompt (mustache, fstring, jinja2).
type PromptTemplateStructure ¶
type PromptTemplateStructure string
PromptTemplateStructure represents the type of prompt template.
const ( PromptTemplateStructureText PromptTemplateStructure = "text" PromptTemplateStructureChat PromptTemplateStructure = "chat" )
type PromptType ¶
type PromptType string
PromptType represents the type of prompt.
const ( PromptTypeMustache PromptType = "mustache" PromptTypeFString PromptType = "fstring" PromptTypeJinja2 PromptType = "jinja2" )
type PromptVersion ¶
type PromptVersion struct {
// contains filtered or unexported fields
}
PromptVersion represents a specific version of a prompt.
func (*PromptVersion) ChangeDescription ¶
func (v *PromptVersion) ChangeDescription() string
ChangeDescription returns the version change description.
func (*PromptVersion) Commit ¶
func (v *PromptVersion) Commit() string
Commit returns the version commit hash.
func (*PromptVersion) ExtractVariables ¶
func (v *PromptVersion) ExtractVariables() []string
ExtractVariables returns a list of variable names in the template.
func (*PromptVersion) PromptID ¶
func (v *PromptVersion) PromptID() string
PromptID returns the parent prompt ID.
func (*PromptVersion) Render ¶
func (v *PromptVersion) Render(variables map[string]string) string
Render renders the template with the given variables. Supports mustache-style {{variable}} placeholders.
func (*PromptVersion) RenderWithDefault ¶
func (v *PromptVersion) RenderWithDefault(variables map[string]string, defaultValue string) string
RenderWithDefault renders the template with the given variables, using default values for missing variables.
func (*PromptVersion) Template ¶
func (v *PromptVersion) Template() string
Template returns the version template.
type PromptVersionOption ¶
type PromptVersionOption func(*promptVersionOptions)
PromptVersionOption is a functional option for configuring a PromptVersion.
func WithVersionChangeDescription ¶
func WithVersionChangeDescription(changeDescription string) PromptVersionOption
WithVersionChangeDescription sets the change description for the version.
func WithVersionTags ¶
func WithVersionTags(tags ...string) PromptVersionOption
WithVersionTags sets the tags for the version.
func WithVersionType ¶
func WithVersionType(promptType PromptType) PromptVersionOption
WithVersionType sets the type for the version.
type PropagatingRoundTripper ¶
type PropagatingRoundTripper struct {
// contains filtered or unexported fields
}
PropagatingRoundTripper wraps an http.RoundTripper to automatically inject distributed trace headers into outgoing requests.
func NewPropagatingRoundTripper ¶
func NewPropagatingRoundTripper(transport http.RoundTripper) *PropagatingRoundTripper
NewPropagatingRoundTripper creates a new PropagatingRoundTripper.
type RecordedFeedback ¶
RecordedFeedback represents a feedback score captured during local recording.
type RecordedSpan ¶
type RecordedSpan struct {
ID string
TraceID string
ParentSpanID string
Name string
Type string
StartTime time.Time
EndTime time.Time
Input any
Output any
Metadata map[string]any
Tags []string
Model string
Provider string
Children []*RecordedSpan
Feedback []*RecordedFeedback
}
RecordedSpan represents a span captured during local recording.
type RecordedTrace ¶
type RecordedTrace struct {
ID string
Name string
StartTime time.Time
EndTime time.Time
Input any
Output any
Metadata map[string]any
Tags []string
Spans []*RecordedSpan
Feedback []*RecordedFeedback
}
RecordedTrace represents a trace captured during local recording.
type RecordingClient ¶
type RecordingClient struct {
// contains filtered or unexported fields
}
RecordingClient is a client that records traces locally instead of sending to server.
func NewRecordingClient ¶
func NewRecordingClient(projectName string) *RecordingClient
NewRecordingClient creates a new recording client for local testing.
func RecordTracesLocally ¶
func RecordTracesLocally(projectName string) *RecordingClient
RecordTracesLocally returns a recording client for local testing. Usage:
client := opik.RecordTracesLocally("my-project")
trace, _ := client.Trace(ctx, "test-trace")
// ... do work ...
trace.End(ctx)
traces := client.Recording().Traces()
func (*RecordingClient) Recording ¶
func (c *RecordingClient) Recording() *LocalRecording
Recording returns the local recording storage.
func (*RecordingClient) Trace ¶
func (c *RecordingClient) Trace(ctx context.Context, name string, opts ...TraceOption) (*RecordingTrace, error)
Trace creates a new trace and records it locally.
type RecordingSpan ¶
type RecordingSpan struct {
// contains filtered or unexported fields
}
RecordingSpan is a span that records locally.
func (*RecordingSpan) AddFeedbackScore ¶
func (s *RecordingSpan) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error
AddFeedbackScore adds a feedback score to this span.
func (*RecordingSpan) End ¶
func (s *RecordingSpan) End(ctx context.Context, opts ...SpanOption) error
End ends the span.
func (*RecordingSpan) Span ¶
func (s *RecordingSpan) Span(ctx context.Context, name string, opts ...SpanOption) (*RecordingSpan, error)
Span creates a child span.
func (*RecordingSpan) TraceID ¶
func (s *RecordingSpan) TraceID() string
TraceID returns the trace ID.
type RecordingTrace ¶
type RecordingTrace struct {
// contains filtered or unexported fields
}
RecordingTrace is a trace that records locally.
func (*RecordingTrace) AddFeedbackScore ¶
func (t *RecordingTrace) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error
AddFeedbackScore adds a feedback score to this trace.
func (*RecordingTrace) End ¶
func (t *RecordingTrace) End(ctx context.Context, opts ...TraceOption) error
End ends the trace.
func (*RecordingTrace) Span ¶
func (t *RecordingTrace) Span(ctx context.Context, name string, opts ...SpanOption) (*RecordingSpan, error)
Span creates a new span under this trace.
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
Span represents a span within a trace in Opik.
func SpanFromContext ¶
SpanFromContext returns the span from the context, or nil if none.
func StartSpan ¶
func StartSpan(ctx context.Context, name string, opts ...SpanOption) (context.Context, *Span, error)
StartSpan creates a new span and attaches it to the context. If there is no parent span in the context, it uses the trace from context. Returns the new context and the span.
func (*Span) AddFeedbackScore ¶
func (s *Span) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error
AddFeedbackScore adds a feedback score to this span.
func (*Span) End ¶
func (s *Span) End(ctx context.Context, opts ...SpanOption) error
End ends the span with optional output.
func (*Span) ParentSpanID ¶
ParentSpanID returns the parent span ID, or empty string if none.
type SpanBatchItem ¶
type SpanBatchItem struct {
Span *Span
}
SpanBatchItem represents a span to be created.
func (SpanBatchItem) Type ¶
func (s SpanBatchItem) Type() string
type SpanInfo ¶
type SpanInfo struct {
ID string
TraceID string
ParentSpanID string
Name string
Type string
StartTime time.Time
EndTime time.Time
Model string
Provider string
}
SpanInfo represents basic span information.
type SpanOption ¶
type SpanOption func(*spanOptions)
SpanOption is a functional option for configuring a Span.
func WithSpanInput ¶
func WithSpanInput(input any) SpanOption
WithSpanInput sets the input for the span.
func WithSpanMetadata ¶
func WithSpanMetadata(metadata map[string]any) SpanOption
WithSpanMetadata sets the metadata for the span.
func WithSpanModel ¶
func WithSpanModel(model string) SpanOption
WithSpanModel sets the model name for LLM spans.
func WithSpanOutput ¶
func WithSpanOutput(output any) SpanOption
WithSpanOutput sets the output for the span.
func WithSpanProvider ¶
func WithSpanProvider(provider string) SpanOption
WithSpanProvider sets the provider name for LLM spans.
func WithSpanTags ¶
func WithSpanTags(tags ...string) SpanOption
WithSpanTags sets the tags for the span.
func WithSpanType ¶
func WithSpanType(spanType string) SpanOption
WithSpanType sets the type of the span (general, llm, tool, guardrail).
type StreamAccumulator ¶
type StreamAccumulator struct {
// contains filtered or unexported fields
}
StreamAccumulator accumulates streaming chunks into a complete response.
func NewStreamAccumulator ¶
func NewStreamAccumulator() *StreamAccumulator
NewStreamAccumulator creates a new stream accumulator.
func (*StreamAccumulator) AddChunk ¶
func (a *StreamAccumulator) AddChunk(chunk StreamChunk)
AddChunk adds a chunk to the accumulator.
func (*StreamAccumulator) ChunkCount ¶
func (a *StreamAccumulator) ChunkCount() int
ChunkCount returns the number of chunks received.
func (*StreamAccumulator) Content ¶
func (a *StreamAccumulator) Content() string
Content returns the accumulated content.
func (*StreamAccumulator) Duration ¶
func (a *StreamAccumulator) Duration() time.Duration
Duration returns the duration from first to last chunk.
func (*StreamAccumulator) FinishReason ¶
func (a *StreamAccumulator) FinishReason() string
FinishReason returns the finish reason.
func (*StreamAccumulator) Metadata ¶
func (a *StreamAccumulator) Metadata() map[string]any
Metadata returns the accumulated metadata.
func (*StreamAccumulator) TimeToFirstChunk ¶
func (a *StreamAccumulator) TimeToFirstChunk(streamStart time.Time) time.Duration
TimeToFirstChunk returns the time to first chunk (should be set externally).
func (*StreamAccumulator) ToOutput ¶
func (a *StreamAccumulator) ToOutput() map[string]any
ToOutput returns the accumulator as a span output.
func (*StreamAccumulator) TotalTokens ¶
func (a *StreamAccumulator) TotalTokens() int
TotalTokens returns the total token count.
type StreamChunk ¶
type StreamChunk struct {
Content string
Index int
IsFirst bool
IsLast bool
Timestamp time.Time
TokenCount int
FinishReason string
Metadata map[string]any
}
StreamChunk represents a chunk of streaming data.
type StreamChunkOption ¶
type StreamChunkOption func(*StreamChunk)
StreamChunkOption configures a stream chunk.
func WithChunkFinishReason ¶
func WithChunkFinishReason(reason string) StreamChunkOption
WithChunkFinishReason sets the finish reason.
func WithChunkMetadata ¶
func WithChunkMetadata(key string, value any) StreamChunkOption
WithChunkMetadata adds metadata to a chunk.
func WithChunkTokenCount ¶
func WithChunkTokenCount(count int) StreamChunkOption
WithChunkTokenCount sets the token count for a chunk.
type StreamHandler ¶
type StreamHandler interface {
// HandleChunk processes a chunk of data.
HandleChunk(chunk StreamChunk) error
// Finalize is called when the stream ends.
Finalize() error
}
StreamHandler is a generic interface for processing streams.
type StreamingSpan ¶
type StreamingSpan struct {
// contains filtered or unexported fields
}
StreamingSpan wraps a span for streaming operations.
func NewStreamingSpan ¶
func NewStreamingSpan(span *Span) *StreamingSpan
NewStreamingSpan creates a new streaming span wrapper.
func StartStreamingSpan ¶
func StartStreamingSpan(ctx context.Context, name string, opts ...SpanOption) (context.Context, *StreamingSpan, error)
StartStreamingSpan starts a new span configured for streaming.
func (*StreamingSpan) Accumulator ¶
func (s *StreamingSpan) Accumulator() *StreamAccumulator
Accumulator returns the stream accumulator.
func (*StreamingSpan) AddChunk ¶
func (s *StreamingSpan) AddChunk(content string, opts ...StreamChunkOption)
AddChunk adds a chunk and tracks it.
func (*StreamingSpan) End ¶
func (s *StreamingSpan) End(ctx context.Context, opts ...SpanOption) error
End ends the streaming span with accumulated data.
func (*StreamingSpan) OnChunk ¶
func (s *StreamingSpan) OnChunk(fn func(chunk StreamChunk))
OnChunk sets a callback for when chunks are received.
func (*StreamingSpan) TraceID ¶
func (s *StreamingSpan) TraceID() string
TraceID returns the trace ID.
type Trace ¶
type Trace struct {
// contains filtered or unexported fields
}
Trace represents an execution trace in Opik.
func StartTrace ¶
func StartTrace(ctx context.Context, client *Client, name string, opts ...TraceOption) (context.Context, *Trace, error)
StartTrace creates a new trace and attaches it to the context. Returns the new context and the trace.
func TraceFromContext ¶
TraceFromContext returns the trace from the context, or nil if none.
func (*Trace) AddFeedbackScore ¶
func (t *Trace) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error
AddFeedbackScore adds a feedback score to this trace.
func (*Trace) End ¶
func (t *Trace) End(ctx context.Context, opts ...TraceOption) error
End ends the trace with optional output.
func (*Trace) ProjectName ¶
ProjectName returns the project name.
type TraceBatchItem ¶
type TraceBatchItem struct {
Trace *Trace
}
TraceBatchItem represents a trace to be created.
func (TraceBatchItem) Type ¶
func (t TraceBatchItem) Type() string
type TraceOption ¶
type TraceOption func(*traceOptions)
TraceOption is a functional option for configuring a Trace.
func WithTraceInput ¶
func WithTraceInput(input any) TraceOption
WithTraceInput sets the input for the trace.
func WithTraceMetadata ¶
func WithTraceMetadata(metadata map[string]any) TraceOption
WithTraceMetadata sets the metadata for the trace.
func WithTraceOutput ¶
func WithTraceOutput(output any) TraceOption
WithTraceOutput sets the output for the trace.
func WithTraceProject ¶
func WithTraceProject(projectName string) TraceOption
WithTraceProject sets the project name for the trace.
func WithTraceTags ¶
func WithTraceTags(tags ...string) TraceOption
WithTraceTags sets the tags for the trace.
func WithTraceThreadID ¶
func WithTraceThreadID(threadID string) TraceOption
WithTraceThreadID sets the thread ID for the trace.
type TracingStreamHandler ¶
type TracingStreamHandler struct {
// contains filtered or unexported fields
}
TracingStreamHandler wraps a StreamHandler to add tracing.
func NewTracingStreamHandler ¶
func NewTracingStreamHandler(inner StreamHandler, span *Span) *TracingStreamHandler
NewTracingStreamHandler creates a tracing stream handler.
func (*TracingStreamHandler) Finalize ¶
func (h *TracingStreamHandler) Finalize() error
Finalize ends the stream and the span.
func (*TracingStreamHandler) HandleChunk ¶
func (h *TracingStreamHandler) HandleChunk(chunk StreamChunk) error
HandleChunk processes a chunk and tracks it.
func (*TracingStreamHandler) StreamingSpan ¶
func (h *TracingStreamHandler) StreamingSpan() *StreamingSpan
StreamingSpan returns the streaming span for ending.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
opik
command
|
|
|
Package evaluation provides a framework for evaluating LLM outputs.
|
Package evaluation provides a framework for evaluating LLM outputs. |
|
heuristic
Package heuristic provides rule-based evaluation metrics that don't require LLM calls.
|
Package heuristic provides rule-based evaluation metrics that don't require LLM calls. |
|
llm
Package llm provides LLM-based evaluation metrics.
|
Package llm provides LLM-based evaluation metrics. |
|
examples
|
|
|
basic
command
|
|
|
connectivity-test
command
Package main provides a connectivity test with HTTP debug output.
|
Package main provides a connectivity test with HTTP debug output. |
|
debug-test
command
Package main provides diagnostic tools for testing and debugging Opik traces and spans.
|
Package main provides diagnostic tools for testing and debugging Opik traces and spans. |
|
integrations
|
|
|
omnillm
Package omnillm provides Opik integration for the omnillm LLM wrapper library.
|
Package omnillm provides Opik integration for the omnillm LLM wrapper library. |
|
internal
|
|
|
api
Code generated by ogen, DO NOT EDIT.
|
Code generated by ogen, DO NOT EDIT. |
|
Package llmops provides an omniobserve/llmops adapter for go-opik.
|
Package llmops provides an omniobserve/llmops adapter for go-opik. |
|
Package testutil provides testing utilities for the Opik SDK.
|
Package testutil provides testing utilities for the Opik SDK. |