Console-based Tracing implementation with colored, formatted output.
Prints trace events to standard output with ANSI color formatting for improved readability during development and debugging. Returns Result[Unit] to support functional composition.
== Content is withheld unless enabled ==
By default it prints metadata only: each event's type, timestamp, model, ids, tool names, success flags, durations, token counts and costs. Text that may hold personal or confidential data - the query of AgentInitialized, the content of CompletionReceived, the input and output of ToolExecuted, the field values of a CustomEvent (whose data is defined by whoever emits it, so may hold anything), and the message and context of an error - is replaced by [withheld: N chars] (a CustomEvent shows its field names). Standard output is often collected into logs kept outside the controls applied to the conversation itself (#2311).
Pass captureContent = true, or set llm4s.tracing.console.captureContent = true (LLM4S_TRACING_CONSOLE_CAPTURE_CONTENT=true) when the tracer is built from Llm4sConfig.tracing(), to print that text as well, truncated for readability.
== Features ==
Color-coded output by event type (errors in red, success in green, etc.)
Visual separators and headers for different trace sections
The ConsoleTracing and LangfuseTracing implementations emit a TraceEvent.CompletionReceived event containing the completion ID, the supplied model identifier, the number of tool calls in the assistant message, and the message content.
Implementations should report tracing failures through the returned result rather than throwing exceptions.
Value parameters
completion
the model response whose details are to be traced
model
the model identifier to associate with this completion
Attributes
Returns
Right(()) when the tracing call is handled successfully, including when a no-op backend discards it, or Left(error) if tracing fails. Callers may ignore or log tracing failures.
Records an error together with context describing where it occurred.
Records an error together with context describing where it occurred.
The ConsoleTracing and LangfuseTracing implementations emit a TraceEvent.ErrorOccurred event containing the supplied error and context.
Implementations should report tracing failures through the returned result rather than throwing exceptions.
Value parameters
context
a description of the operation or circumstances in which the error occurred, such as "fetching weather data"; defaults to an empty string
error
the error to record
Attributes
Returns
Right(()) when the tracing call is handled successfully, including when a no-op backend discards it, or Left(error) if tracing fails. Callers may ignore or log tracing failures.
Handles a structured trace event using this tracing backend. Implementations should report tracing failures through the returned result rather than throwing exceptions.
Handles a structured trace event using this tracing backend. Implementations should report tracing failures through the returned result rather than throwing exceptions.
Value parameters
event
the structured event to trace
Attributes
Returns
Right(()) when the tracing call is handled successfully, including when a no-op backend discards the event, or Left(error) if tracing fails. Callers may ignore or log tracing failures.
The ConsoleTracing and LangfuseTracing implementations emit a TraceEvent.TokenUsageRecorded event containing the supplied usage, model identifier, and operation label.
Implementations should report tracing failures through the returned result rather than throwing exceptions.
Value parameters
model
the model identifier to associate with this usage
operation
a caller-defined label describing the operation, such as "completion"
usage
the token usage reported for the operation
Attributes
Returns
Right(()) when the tracing call is handled successfully, including when a no-op backend discards it, or Left(error) if tracing fails. Callers may ignore or log tracing failures.
Records a tool call using the supplied tool name, input, and output.
Records a tool call using the supplied tool name, input, and output.
The ConsoleTracing and LangfuseTracing implementations emit a TraceEvent.ToolExecuted event with zero duration and the success flag set to true. They do not measure the duration or determine whether the tool execution succeeded.
Implementations should report tracing failures through the returned result rather than throwing exceptions.
Value parameters
input
the input supplied to the tool
output
the output returned by the tool
toolName
the name of the tool that was called
Attributes
Returns
Right(()) when the tracing call is handled successfully, including when a no-op backend discards it, or Left(error) if tracing fails. Callers may ignore or log tracing failures.
Emits a named CustomEvent with no additional data payload.
Emits a named CustomEvent with no additional data payload.
Wraps the string in a TraceEvent.CustomEvent with an empty JSON object as its data field before delegating to traceEvent(TraceEvent). Use the typed overload for events that carry structured data.
Value parameters
event
Human-readable event name forwarded as CustomEvent.name