For the complete documentation index, see llms.txt. This page is also available as Markdown.

Instrument custom Python

Recipe — instrument a custom Python pipeline using @trace and span().

For pipelines that don't use one of the supported framework or provider adapters, use the manual instrumentation primitives from layerlens.instrument:

from layerlens.instrument import trace, span

@trace
def run_pipeline(query: str):
 with span("retrieval"):
 chunks = retrieve(query)
 with span("llm-call"):
 answer = llm_call(query, chunks)
 return answer

The decorator and context manager emit spans to the configured HTTP sink. Tags, status, and error capture are handled automatically.

For full canonical patterns, see samples/integrations/openai_instrumented.py — uses @trace and span() alongside instrument_openai().

See also

Last updated

Was this helpful?