org.llm4s.trace.Tracing
See theTracing companion object
@Stable
trait Tracing
Type-safe tracing interface for observability and debugging.
Provides a functional approach to tracing with Result[Unit] return types for proper error handling and composition. Supports multiple backends including console output, Langfuse, OpenTelemetry and custom implementations.
== Implementations ==
- ConsoleTracing - Colored console output for development (core); metadata only unless
llm4s.tracing.console.captureContentis set - NoOpTracing - Silent implementation for testing/disabled tracing (core)
LangfuseTracing- Production observability via Langfuse (llm4s-observability)OpenTelemetryTracing- OTLP export (llm4s-observability-otel)
== Usage ==
// Create from settings
val tracing = Tracing.create(settings)
// Or use directly
val tracing: Tracing = new ConsoleTracing()
// Trace events functionally
for {
_ <- tracing.traceEvent(TraceEvent.AgentInitialized("query", tools))
_ <- tracing.traceTokenUsage(usage, "gpt-4", "completion")
} yield ()
== Agent state ==
There is no traceAgentState(AgentState). An agent run reports its end with TraceEvent.AgentRunEnded; the agent's per-step events arrive as CustomEvents named graph.* and agent.*.
== Composition ==
Tracers can be composed using TracingComposer:
val combined = TracingComposer.combine(consoleTracer, langfuseTracer)
val filtered = TracingComposer.filter(tracer)(_.eventType == "error_occurred")
Attributes
- See also
-
TraceEvent for available event types
TracingComposer for composition utilities
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class ConsoleTracingclass LangfuseTracingclass NoOpTracingclass OpenTelemetryTracingclass TraceCollectorTracing[F]
Members list
In this article