No framework (Python standard library)
Send OpenTelemetry GenAI spans from a hand-written agent with one dependency-free Python file, for teams that cannot add the OpenTelemetry SDK.
Python
- Upstream docs: OpenTelemetry GenAI span conventions
- Upstream docs: OTLP/HTTP JSON encoding
Setup (from examples/instrumentation/python-stdlib)
# telumin_stdlib.py is one file with no dependencies: copy it next to your code.
# 1. One tracer per process. The owner goes on the resource (C2).
# This example writes a file; in production pass endpoint="http://127.0.0.1:4318" instead.
tracer = Tracer(service_name="refund-service", owner="payments-team", service_version="1.4.0", file_path=sys.argv[1])Record the approval in the tool (from examples/instrumentation/python-stdlib)
def run_refund_agent(request):
instructions = "Handle refund requests."
# 2. One trace per run: name + id + version identify the agent (C1).
with tracer.agent_run("refund-agent", "refund-agent-v1", "v1", model="stub-model", provider="stub") as run:
step = stub_model(1) # your model call, given instructions + request
# 3. One execute_tool span per action (C3). Only the tool name and call id are recorded.
with run.tool(step["tool"], call_id=step["call_id"]) as tool_span:
decision, reason = ask_human(step["args"]["amount"])
# 4. The human decision lands on the tool's span (C4).
tool_span.record_approval(decision, "alice@example.com", reason=reason, tool_call_id=step["call_id"])
del instructions, request
return stub_model(2)["text"]Run (from examples/instrumentation/python-stdlib)
answer = run_refund_agent("Please refund order A-1001, 40 EUR.")
# 5. Send once at the end of the job. A failed send never raises.
tracer.flush()- Copy examples/instrumentation/python-stdlib/telumin_stdlib.py into your project. It uses urllib and json only.
- It has no way to record prompts, replies or tool arguments, so no content leaves your process.
- A failed send is reported on stderr and never raises into your code.
- Call flush() once at the end of a job, or after each run in a long-lived process.
Runnable example, tested in CI
examples/instrumentation/python-stdlib runs offline with a mocked model, writes OTLP JSON, and goes through the check on every change. Result: C1 green, C2 green, C3 green, C4 green (one approval recorded with record_approval).
Owner and approvals
No instrumentation package records who owns an agent or who approved a tool call. Add both with telumin-otel, as the examples do.
Check the result
To check the result, export the spans as OTLP JSON (or send them through the collector tap) and drop the file on the free check. The check runs in your browser tab.