Instrument custom Python
Recipe — instrument a custom Python pipeline using @trace and span().
Last updated
Was this helpful?
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 answerThe 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().
Last updated
Was this helpful?
Was this helpful?