teff.observability¶
teff.observability
¶
Graph-run observability: full traces (topology, node spans, LLM payloads).
Usage::
from teff.observability import (
GraphObserver,
JsonlExporter,
SQLiteExporter,
topology_from_graph,
)
observer = GraphObserver(
"my-flow",
exporter=SQLiteExporter("./traces.db"),
topology=topology_from_graph(graph),
)
await graph.run(state, tracer=observer.tracer,
on_llm_payload=observer.on_llm_payload)
observer.export()
Modules:
| Name | Description |
|---|---|
api |
FastAPI router exposing stored traces as a dashboard API. |
builder |
Build a :class: |
collector |
Collect a full graph-run trace into a single :class: |
exporter |
Exporters for :class: |
model |
Observability data model for a graph run. |
push |
Remote trace exporters: push a completed :class: |
server |
Standalone trace server: ingest + dashboard ( |
topology |
Graph topology snapshot — the node/edge shape for the dashboard. |
Classes:
| Name | Description |
|---|---|
CompositeExporter |
Fan one run out to several exporters (SQLite + remote sinks). |
GraphObserver |
Assemble a :class: |
GraphTopology |
A node/edge snapshot of the compiled graph (for visualisation). |
HttpExporter |
POST each completed run as JSON to a remote ingest endpoint. |
JsonlExporter |
Append each run as one JSON line to a newline-delimited file. |
LLMCall |
One model call with the full request/response payload. |
LangfuseExporter |
Push runs to a Langfuse instance via the public traces API. |
LangsmithExporter |
Push runs to LangSmith via the |
NodeSpan |
One node execution: timing, outcome, its LLM calls and tool calls. |
Run |
A single executed run, ready to export or serve over the API. |
SQLiteExporter |
Store runs in SQLite tables |
SpanEvent |
One step of a node's execution, in chronological order. |
ToolCall |
One tool invocation: what the model requested and what ran. |
TraceExporter |
Persist a completed :class: |
Functions:
| Name | Description |
|---|---|
build_observability |
Assemble a :class: |
build_observer_factory |
Like :func: |
build_remote_exporter |
Construct a remote exporter from one |
topology_from_graph |
Capture |
CompositeExporter
¶
Bases: TraceExporter
Fan one run out to several exporters (SQLite + remote sinks).
A failure in one sink is logged and swallowed so the remaining sinks (and the workflow that produced the run) keep working.
Source code in teff/observability/exporter.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
GraphObserver
¶
Assemble a :class:Run from graph events and forward it to an exporter.
Methods:
| Name | Description |
|---|---|
export |
Persist the collected :class: |
on_llm_payload |
Sink for the run's |
Source code in teff/observability/collector.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
export
¶
export()
Persist the collected :class:Run and return its backend run id.
Returns None when no exporter is attached (tracing disabled) or
the backend does not expose ids.
Source code in teff/observability/collector.py
245 246 247 248 249 250 251 252 253 | |
on_llm_payload
async
¶
on_llm_payload(provider, model, messages, response, usage, latency_ms, cached)
Sink for the run's on_llm_payload channel.
Source code in teff/observability/collector.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
GraphTopology
dataclass
¶
A node/edge snapshot of the compiled graph (for visualisation).
Source code in teff/observability/model.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
HttpExporter
¶
Bases: TraceExporter
POST each completed run as JSON to a remote ingest endpoint.
The body is :meth:Run.to_dict plus created_at (seconds since the
epoch) so the receiving side can order runs. Sends are asynchronous:
:meth:export returns immediately, :meth:close drains the queue.
Source code in teff/observability/push.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
JsonlExporter
¶
Bases: TraceExporter
Append each run as one JSON line to a newline-delimited file.
Source code in teff/observability/exporter.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
LLMCall
dataclass
¶
One model call with the full request/response payload.
Source code in teff/observability/model.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
LangfuseExporter
¶
Bases: TraceExporter
Push runs to a Langfuse instance via the public traces API.
Requires host plus a public_key/secret_key pair (Basic
auth). Each node becomes a span observation and every LLM call a
generation observation attached to its node.
Source code in teff/observability/push.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
LangsmithExporter
¶
Bases: TraceExporter
Push runs to LangSmith via the /runs/batch endpoint.
Requires an API key (x-api-key header). The run becomes a chain
run, each node a child chain run, and each LLM call an llm run.
project is passed as extra metadata so the UI can group by project.
Source code in teff/observability/push.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
NodeSpan
dataclass
¶
One node execution: timing, outcome, its LLM calls and tool calls.
Source code in teff/observability/model.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
Run
dataclass
¶
A single executed run, ready to export or serve over the API.
Source code in teff/observability/model.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
SQLiteExporter
¶
Bases: TraceExporter
Store runs in SQLite tables runs / nodes / llm_calls.
The runs table also carries the graph topology as JSON, and the
metadata needed by a dashboard (owner, checkpoint id, status, tokens).
Methods:
| Name | Description |
|---|---|
get_run |
Full run payload: metadata, topology, node spans, LLM calls. |
list_runs |
Dashboard rows (no payloads) with filtering and pagination. |
update_run |
Patch a run's tags / notes. Returns False if the run doesn't exist. |
Source code in teff/observability/exporter.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
get_run
¶
get_run(run_id)
Full run payload: metadata, topology, node spans, LLM calls.
Source code in teff/observability/exporter.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
list_runs
¶
list_runs(limit=100, offset=0, status=None, name=None, owner=None, tag=None)
Dashboard rows (no payloads) with filtering and pagination.
Returns {"items": [...], "total": n} where total is the count
before pagination, so the UI can render a page size / total.
name / owner are case-insensitive substrings, tag matches an
exact tag, status matches the run status exactly.
Source code in teff/observability/exporter.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
update_run
¶
update_run(run_id, *, tags=None, notes=None)
Patch a run's tags / notes. Returns False if the run doesn't exist.
Source code in teff/observability/exporter.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
SpanEvent
dataclass
¶
One step of a node's execution, in chronological order.
kind is "llm" or "tool" and index points into the
span's llm_calls / tool_calls lists. Together they let a UI
render the exact sequence a node followed — LLM call, tool call and
its result, next LLM call, and so on — instead of two separate piles.
Source code in teff/observability/model.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
ToolCall
dataclass
¶
One tool invocation: what the model requested and what ran.
Tool calls are parsed out of the LLM message payloads (assistant
tool_calls blocks matched to the following role: tool results),
so a node's tool usage is a first-class citizen, not buried in the raw
messages. ok is False when the tool returned an "Error: ..."
result.
Source code in teff/observability/model.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
TraceExporter
¶
Bases: ABC
Persist a completed :class:Run to some backend.
Methods:
| Name | Description |
|---|---|
close |
Release any resources held by the exporter. |
export |
Persist run and return its backend run id ( |
Source code in teff/observability/exporter.py
23 24 25 26 27 28 29 30 31 32 33 34 35 | |
close
abstractmethod
¶
close()
Release any resources held by the exporter.
Source code in teff/observability/exporter.py
33 34 35 | |
export
abstractmethod
¶
export(run)
Persist run and return its backend run id (None if unknown).
Idempotent when the store uses run ids.
Source code in teff/observability/exporter.py
26 27 28 29 30 31 | |
build_observability
¶
build_observability(config, *, base_dir='.', graph=None, name='workflow')
Assemble a :class:GraphObserver from an observability: block.
Returns None when the block is missing or declares no sinks. The
observer is wired with the graph topology so remote exporters and the
dashboard can render the flow.
Source code in teff/observability/builder.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
build_observer_factory
¶
build_observer_factory(config, *, base_dir='.', graph=None, name='workflow')
Like :func:build_observability but for repeated runs.
Returns a zero-arg callable that yields a fresh observer per run while
sharing one set of exporters — the right shape for a daemon that traces
every tick. None when observability is not configured.
Source code in teff/observability/builder.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
build_remote_exporter
¶
build_remote_exporter(spec, *, base_dir='.')
Construct a remote exporter from one observability.export entry.
Source code in teff/observability/builder.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
topology_from_graph
¶
topology_from_graph(graph)
Capture {nodes, edges} from a compiled :class:~teff.graph.Graph.
Each node is {"id", "type"}; each edge is {"source", "target",
"condition"} (condition omitted when unconditional).
Source code in teff/observability/topology.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |