Documentation
¶
Index ¶
- Constants
- func ContextWithPropagatedLLMSpan(ctx context.Context, span *PropagatedLLMSpan) context.Context
- func Flush()
- func FlushSync()
- func PublicResourceBaseURL() string
- func Start(cfg config.Config, tracer Tracer) (err error)
- func Stop()
- type APMSpan
- type EmbeddedDocument
- type EvaluationConfig
- type ExperimentInfo
- type FinishAPMSpanConfig
- type FinishSpanConfig
- type LLMMessage
- type LLMObs
- func (l *LLMObs) Flush()
- func (l *LLMObs) FlushSync()
- func (l *LLMObs) Run()
- func (l *LLMObs) StartExperimentSpan(ctx context.Context, name string, params ExperimentInfo, cfg StartSpanConfig) (*Span, context.Context)
- func (l *LLMObs) StartSpan(ctx context.Context, kind SpanKind, name string, cfg StartSpanConfig) (*Span, context.Context)
- func (l *LLMObs) Stop()
- func (l *LLMObs) SubmitEvaluation(cfg EvaluationConfig) (err error)
- type Prompt
- type PropagatedLLMSpan
- type RetrievedDocument
- type Span
- func (s *Span) APMTraceID() string
- func (s *Span) AddLink(link SpanLink)
- func (s *Span) Annotate(a SpanAnnotations)
- func (s *Span) Finish(cfg FinishSpanConfig)
- func (s *Span) FinishTime() time.Time
- func (s *Span) Kind() string
- func (s *Span) MLApp() string
- func (s *Span) Name() string
- func (s *Span) SessionID() string
- func (s *Span) SpanID() string
- func (s *Span) StartTime() time.Time
- func (s *Span) TraceID() string
- type SpanAnnotations
- type SpanKind
- type SpanLink
- type StartAPMSpanConfig
- type StartSpanConfig
- type ToolCall
- type ToolDefinition
- type ToolResult
- type Tracer
Constants ¶
const (
// TagKeySessionID is the tag key used to set the session ID for LLMObs spans.
TagKeySessionID = "session_id"
)
Variables ¶
This section is empty.
Functions ¶
func ContextWithPropagatedLLMSpan ¶
func ContextWithPropagatedLLMSpan(ctx context.Context, span *PropagatedLLMSpan) context.Context
ContextWithPropagatedLLMSpan returns a new context with the given PropagatedLLMSpan attached.
func FlushSync ¶ added in v2.9.0
func FlushSync()
FlushSync flushes all buffered LLMObs data and blocks until the send completes.
func PublicResourceBaseURL ¶
func PublicResourceBaseURL() string
PublicResourceBaseURL returns the base URL to access a resource (experiments, projects, etc.)
Types ¶
type APMSpan ¶
type APMSpan interface {
// Finish finishes the span with the given configuration.
Finish(cfg FinishAPMSpanConfig)
// AddLink adds a span link to this span.
AddLink(link SpanLink)
// SpanID returns the span ID.
SpanID() string
// TraceID returns the trace ID.
TraceID() string
// SetBaggageItem sets a baggage item on the span.
SetBaggageItem(key string, value string)
// BaggageItem returns the baggage item value for the given key.
BaggageItem(key string) string
}
APMSpan represents the interface for an APM span.
type EmbeddedDocument ¶
type EmbeddedDocument struct {
// Text is the text content of the document.
Text string `json:"text"`
// Name is the name or title of the document.
Name string `json:"name,omitempty"`
// Score is the relevance score of the document (typically 0.0-1.0).
Score float64 `json:"score,omitempty"`
// ID is the unique identifier of the document.
ID string `json:"id,omitempty"`
}
EmbeddedDocument represents a document used for embedding operations.
type EvaluationConfig ¶
type EvaluationConfig struct {
// Method 1: Direct span/trace ID join
// SpanID is the span ID to evaluate.
SpanID string
// TraceID is the trace ID to evaluate.
TraceID string
// Method 2: Tag-based join
// TagKey is the tag key to search for spans.
TagKey string
// TagValue is the tag value to match for spans.
TagValue string
// Required fields
// Label is the name of the evaluation metric.
Label string
// Value fields (exactly one must be provided)
// CategoricalValue is the categorical value of the evaluation metric.
CategoricalValue *string
// ScoreValue is the score value of the evaluation metric.
ScoreValue *float64
// BooleanValue is the boolean value of the evaluation metric.
BooleanValue *bool
// Optional fields
// Tags are optional string key-value pairs to tag the evaluation metric.
Tags []string
// MLApp is the ML application name. If empty, uses the global config.
MLApp string
// TimestampMS is the timestamp in milliseconds. If zero, uses current time.
TimestampMS int64
}
EvaluationConfig contains configuration for submitting evaluation metrics.
type ExperimentInfo ¶ added in v2.8.0
ExperimentInfo holds the experiment identifiers propagated via baggage to distributed child spans.
type FinishAPMSpanConfig ¶
type FinishAPMSpanConfig struct {
// FinishTime is the finish time for the span.
FinishTime time.Time
// Error is an error to set on the span when finishing.
Error error
}
FinishAPMSpanConfig contains configuration options for finishing an APM span.
type FinishSpanConfig ¶
type FinishSpanConfig struct {
// FinishTime sets a custom finish time for the span. If zero, uses current time.
FinishTime time.Time
// Error sets an error on the span when finishing.
Error error
}
FinishSpanConfig contains configuration options for finishing an LLMObs span.
type LLMMessage ¶
type LLMMessage struct {
// Role is the role of the message sender (e.g., "user", "assistant", "system").
Role string `json:"role"`
// Content is the text content of the message.
Content string `json:"content"`
// ToolCalls are the tool calls made in this message.
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
// ToolResults are the results of tool calls in this message.
ToolResults []ToolResult `json:"tool_results,omitempty"`
}
LLMMessage represents a message in an LLM conversation.
type LLMObs ¶
type LLMObs struct {
// Config contains the LLMObs configuration.
Config *config.Config
// Transport handles sending data to the Datadog backend.
Transport *transport.Transport
// Tracer is the underlying APM tracer.
Tracer Tracer
// contains filtered or unexported fields
}
LLMObs represents the main LLMObs instance that handles span collection and transport.
func ActiveLLMObs ¶
ActiveLLMObs returns the current active LLMObs instance, or an error if LLMObs is not enabled or started.
func (*LLMObs) Flush ¶
func (l *LLMObs) Flush()
Flush forces an immediate flush of anything currently buffered. It does not wait for new items to arrive.
func (*LLMObs) FlushSync ¶ added in v2.9.0
func (l *LLMObs) FlushSync()
FlushSync flushes all currently buffered data and blocks until the HTTP send completes. If the instance has already been stopped, FlushSync returns immediately instead of blocking forever on the unbuffered flushSyncCh send.
func (*LLMObs) Run ¶
func (l *LLMObs) Run()
Run starts the worker loop that processes span events and metrics.
func (*LLMObs) StartExperimentSpan ¶
func (l *LLMObs) StartExperimentSpan(ctx context.Context, name string, params ExperimentInfo, cfg StartSpanConfig) (*Span, context.Context)
StartExperimentSpan starts a new experiment span with the given name and configuration. ExperimentInfo fields are propagated via baggage so distributed child spans inherit them. Returns the created span and a context containing the span.
func (*LLMObs) StartSpan ¶
func (l *LLMObs) StartSpan(ctx context.Context, kind SpanKind, name string, cfg StartSpanConfig) (*Span, context.Context)
StartSpan starts a new LLMObs span with the given kind, name, and configuration. Returns the created span and a context containing the span.
func (*LLMObs) Stop ¶
func (l *LLMObs) Stop()
Stop requests shutdown, drains what’s already in the channels, flushes, and waits.
func (*LLMObs) SubmitEvaluation ¶
func (l *LLMObs) SubmitEvaluation(cfg EvaluationConfig) (err error)
SubmitEvaluation submits an evaluation metric for a span. The span can be identified either by span/trace IDs or by tag key-value pairs.
type Prompt ¶
type Prompt struct {
// ID is the unique identifier for the prompt within the ML app.
ID string `json:"id,omitempty"`
// Version is the version of the prompt.
Version string `json:"version,omitempty"`
// Label is the deployment label (e.g., "production", "staging").
Label string `json:"label,omitempty"`
// Template is the prompt template string.
// Mutually exclusive with ChatTemplate; if both are set, Template is dropped and ChatTemplate is used.
Template string `json:"template,omitempty"`
// ChatTemplate is a list of messages forming the prompt.
// Mutually exclusive with Template; if both are set, Template is dropped and ChatTemplate is used.
ChatTemplate []LLMMessage `json:"chat_template,omitempty"`
// Variables contains the variables used in the prompt template.
Variables map[string]string `json:"variables,omitempty"`
// Tags contains custom tags for the prompt.
Tags map[string]string `json:"tags,omitempty"`
// RAGContextVariables specifies which variables contain RAG context.
RAGContextVariables []string `json:"_dd_context_variable_keys,omitempty"`
// RAGQueryVariables specifies which variables contain RAG queries.
RAGQueryVariables []string `json:"_dd_query_variable_keys,omitempty"`
}
Prompt represents a prompt template used with LLM spans.
type PropagatedLLMSpan ¶
type PropagatedLLMSpan struct {
// MLApp is the ML application name.
MLApp string
// TraceID is the LLMObs trace ID.
TraceID string
// SpanID is the span ID.
SpanID string
// SessionID is the session ID.
SessionID string
}
PropagatedLLMSpan represents LLMObs span context that can be propagated across process boundaries.
func PropagatedLLMSpanFromContext ¶
func PropagatedLLMSpanFromContext(ctx context.Context) (*PropagatedLLMSpan, bool)
PropagatedLLMSpanFromContext retrieves a PropagatedLLMSpan from the context. Returns the span and true if found, nil and false otherwise.
type RetrievedDocument ¶
type RetrievedDocument struct {
// Text is the text content of the document.
Text string `json:"text"`
// Name is the name or title of the document.
Name string `json:"name,omitempty"`
// Score is the relevance score of the document (typically 0.0-1.0).
Score float64 `json:"score,omitempty"`
// ID is the unique identifier of the document.
ID string `json:"id,omitempty"`
}
RetrievedDocument represents a document for retrieval operations.
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
Span represents an LLMObs span with its associated metadata and context.
func ActiveLLMSpanFromContext ¶
ActiveLLMSpanFromContext retrieves the active LLMObs span from the context. Returns the span and true if found, nil and false otherwise.
func (*Span) APMTraceID ¶
APMTraceID returns the trace ID of the underlying APM span.
func (*Span) Annotate ¶
func (s *Span) Annotate(a SpanAnnotations)
Annotate adds annotations to the span using the provided SpanAnnotations.
func (*Span) Finish ¶
func (s *Span) Finish(cfg FinishSpanConfig)
Finish finishes the span with the provided configuration.
func (*Span) FinishTime ¶
FinishTime returns the finish time of this span.
type SpanAnnotations ¶
type SpanAnnotations struct {
// InputText is the text input for the span.
InputText string
// InputMessages are the input messages for LLM spans.
InputMessages []LLMMessage
// InputEmbeddedDocs are the input documents for embedding spans.
InputEmbeddedDocs []EmbeddedDocument
// OutputText is the text output for the span.
OutputText string
// OutputMessages are the output messages for LLM spans.
OutputMessages []LLMMessage
// OutputRetrievedDocs are the output documents for retrieval spans.
OutputRetrievedDocs []RetrievedDocument
// ExperimentInput is the input data for experiment spans.
ExperimentInput any
// ExperimentOutput is the output data for experiment spans.
ExperimentOutput any
// ExperimentExpectedOutput is the expected output for experiment spans.
ExperimentExpectedOutput any
// Prompt is the prompt information for LLM spans.
Prompt *Prompt
// ToolDefinitions are the tool definitions for LLM spans.
ToolDefinitions []ToolDefinition
// Intent is a description of a reason for calling an MCP tool on tool spans
Intent string
// AgentManifest is the agent manifest for agent spans.
AgentManifest string
// Metadata contains arbitrary metadata key-value pairs.
Metadata map[string]any
// Metrics contains numeric metrics key-value pairs.
Metrics map[string]float64
// Tags contains string tags key-value pairs.
Tags map[string]string
// CostTags contains tag keys to propagate to LLMObs cost and token metrics.
// Each key must reference a tag already present on the span.
CostTags []string
}
SpanAnnotations contains data to annotate an LLMObs span with.
type SpanKind ¶
type SpanKind string
SpanKind represents the type of an LLMObs span.
const ( // SpanKindExperiment represents an experiment span for testing and evaluation. SpanKindExperiment SpanKind = "experiment" // SpanKindWorkflow represents a workflow span that orchestrates multiple operations. SpanKindWorkflow SpanKind = "workflow" // SpanKindLLM represents a span for Large Language Model operations. SpanKindLLM SpanKind = "llm" // SpanKindEmbedding represents a span for embedding generation operations. SpanKindEmbedding SpanKind = "embedding" // SpanKindAgent represents a span for AI agent operations. SpanKindAgent SpanKind = "agent" // SpanKindRetrieval represents a span for document retrieval operations. SpanKindRetrieval SpanKind = "retrieval" // SpanKindTask represents a span for general task operations. SpanKindTask SpanKind = "task" // SpanKindTool represents a span for tool usage operations. SpanKindTool SpanKind = "tool" )
type StartAPMSpanConfig ¶
type StartAPMSpanConfig struct {
// SpanType is the type of the APM span.
SpanType string
// StartTime is the start time for the span.
StartTime time.Time
}
StartAPMSpanConfig contains configuration options for starting an APM span.
type StartSpanConfig ¶
type StartSpanConfig struct {
// SessionID sets the session ID for the span.
SessionID string
// ModelName sets the model name for LLM and embedding spans.
ModelName string
// ModelProvider sets the model provider for LLM and embedding spans.
ModelProvider string
// MLApp sets the ML application name for the span.
MLApp string
// StartTime sets a custom start time for the span. If zero, uses current time.
StartTime time.Time
// Name of the tracing integration.
Integration string
}
StartSpanConfig contains configuration options for starting an LLMObs span.
type ToolCall ¶
type ToolCall struct {
// Name is the name of the tool being called.
Name string `json:"name"`
// Arguments are the JSON-encoded arguments passed to the tool.
Arguments json.RawMessage `json:"arguments"`
// ToolID is the unique identifier for this tool call.
ToolID string `json:"tool_id,omitempty"`
// Type is the type of the tool call.
Type string `json:"type,omitempty"`
}
ToolCall represents a call to a tool within an LLM message.
type ToolDefinition ¶
type ToolDefinition struct {
// Name is the name of the tool.
Name string `json:"name"`
// Description is the description of what the tool does.
Description string `json:"description,omitempty"`
// ToolVersion is the version of the tool.
ToolVersion string `json:"version,omitempty"`
// Schema is the JSON schema defining the tool's parameters.
Schema json.RawMessage `json:"schema,omitempty"`
}
ToolDefinition represents a tool definition for LLM spans.
type ToolResult ¶
type ToolResult struct {
// Result is the result returned by the tool.
Result any `json:"result"`
// Name is the name of the tool that was called.
Name string `json:"name,omitempty"`
// ToolID is the unique identifier for the tool call this result corresponds to.
ToolID string `json:"tool_id,omitempty"`
// Type is the type of the tool result.
Type string `json:"type,omitempty"`
}
ToolResult represents the result of a tool call within an LLM message.