windlass.interfaces.tracer¶
tracer
¶
The observability interface.
Windlass instruments every meaningful operation — a model call, a retrieval, a
tool execution, an ingestion run — as a :class:Span. A :class:Tracer decides
what to do with those spans: drop them, print them, or ship them to LangSmith or
Langfuse.
Instrumentation is always on and always cheap. With no tracer configured, spans
resolve to :class:NullTracer, whose span() is a context manager that does
nothing measurable.
Implementers override one method, :meth:Tracer.start_span.
Example
from windlass.providers.observability.console import ConsoleTracer tracer = ConsoleTracer(enabled=False) with tracer.span("demo", kind="llm") as span: ... _ = span.set_output("done") span.name 'demo'
Span
¶
Span(
name: str,
*,
kind: str = "chain",
parent_id: str | None = None,
metadata: dict[str, Any] | None = None,
trace_id: str | None = None
)
One timed, attributed unit of work.
Spans are created by :meth:Tracer.span and finished automatically when the
context manager exits. Exceptions are recorded before propagating, so a
failed run is still fully traced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Human readable operation name. |
required |
kind
|
str
|
One of :data: |
'chain'
|
parent_id
|
str | None
|
Enclosing span's id, when nested. |
None
|
metadata
|
dict[str, Any] | None
|
Static attributes attached at creation. |
None
|
trace_id
|
str | None
|
Groups spans belonging to one top-level request. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Unique span id. |
|
started_at |
Monotonic start time. |
|
ended_at |
float | None
|
Monotonic end time, set on :meth: |
error |
str | None
|
Error message, when the span failed. |
usage |
Usage | None
|
Token accounting, for model spans. |
Source code in src\windlass\interfaces\tracer.py
set_input
¶
set_output
¶
set_usage
¶
set_metadata
¶
set_error
¶
end
¶
attach_native
¶
native
¶
to_dict
¶
Return a JSON-safe representation of the span.
Source code in src\windlass\interfaces\tracer.py
Tracer
¶
Tracer(
*,
enabled: bool = True,
project: str | None = None,
tags: tuple[str, ...] = (),
name: str | None = None,
**config: Any
)
Bases: Component
Abstract tracing backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
Master switch. Disabled tracers still create spans (so code paths are identical) but never export them. |
True
|
project
|
str | None
|
Project / session name shown in the backend's UI. |
None
|
tags
|
tuple[str, ...]
|
Tags applied to every span. |
()
|
name
|
str | None
|
Component name. |
None
|
**config
|
Any
|
Backend-specific options. |
{}
|
Example
Implementing a tracer takes one method::
class PrintTracer(Tracer):
provider_name = "print"
def start_span(self, span): ...
def end_span(self, span):
print(span.to_dict())
Source code in src\windlass\interfaces\tracer.py
start_span
abstractmethod
¶
Called when a span begins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
span
|
Span
|
The span that just started. Attach a backend object with
:meth: |
required |
end_span
¶
Called when a span ends, successfully or not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
span
|
Span
|
The finished span. |
required |
flush
¶
Force any buffered spans to be exported.
Backends that batch should override this; a process that exits without flushing loses its last traces.
span
¶
Open a span around a block of work.
Spans nest automatically: a span opened inside another becomes its child, which is what produces a readable trace tree from plain code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Operation name. |
required |
kind
|
str
|
One of :data: |
'chain'
|
inputs
|
Any
|
The operation's input, recorded immediately. |
None
|
**metadata
|
Any
|
Extra attributes. |
{}
|
Yields:
| Type | Description |
|---|---|
Span
|
The live :class: |
Raises:
| Type | Description |
|---|---|
Exception
|
Anything the block raises, after recording it. |
Example
from windlass.providers.observability.console import ConsoleTracer with ConsoleTracer(enabled=False).span("work", kind="tool") as s: ... s.set_output(42)
Source code in src\windlass\interfaces\tracer.py
current_span
¶
event
¶
Record a zero-duration event on the current span.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Event name. |
required |
**fields
|
Any
|
Event attributes. |
{}
|