Core Logging
Log Function Wrapper
The log
function wrapper allows you to wrap functions with spans of different types. It serves two main purposes:
- It tells our logger to wrap the function contents as a span (you can specify the type in the first argument - by default a workflow span is created).
- If there is no current trace when you execute a function wrapped in
log
, it will create a single span trace.
Usage
Span Types
The log
function wrapper supports different span types:
- workflow: A span that can have child spans, useful for nesting several child spans to denote a thread within a trace. If you wrap a parent function with
log
, calls that are made within that scope are automatically logged in the same trace. - llm: Captures the input, output, and settings of an LLM call. This span gets automatically created when our client library wrappers (OpenAI and Anthropic) are used. Cannot have nested children.
- retriever: Contains the output documents of a retrieval operation.
- tool: Captures the input and output of a tool call. Used to decorate functions that are invoked as tools.
Examples
Workflow Span with Nested LLM Calls
Create a trace with a workflow span and nested LLM spans:
Retriever Span
Log a retriever function. If the output of the function is an array, it will automatically capture it as documents in the span: