Scaling & Observability
Hands-on lab with starter code you can copy + run, and guided steps to produce the artifact for this module.
Setup
- Open a fresh terminal in a new folder, e.g.
mkdir lab-10 && cd lab-10. - Create a Python 3.11 venv:
python -m venv .venv && source .venv/bin/activate. - Install the dependencies noted on each starter snippet (the small pip install … line above the code).
- Copy each starter into a file with the suggested name, then run it and capture the output.
Starter code
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(ConsoleSpanExporter()))
tracer = trace.get_tracer("agent")
def traced_step(name, fn, *a, **kw):
with tracer.start_as_current_span(name) as span:
span.set_attribute("input", str(a)[:200])
out = fn(*a, **kw)
span.set_attribute("output", str(out)[:200])
return outpython 10_01_lab.pyclass Budget:
def __init__(self, max_usd):
self.spent = 0.0; self.max = max_usd
def charge(self, in_tok, out_tok, in_price, out_price):
cost = in_tok*in_price/1000 + out_tok*out_price/1000
self.spent += cost
if self.spent > self.max:
raise RuntimeError(f"budget exceeded: {self.spent:.4f} > {self.max}")
return costpython 10_02_lab.pyGuided steps
Work through each step in order. Stop when your output matches the expected artifact — then push your work to your lab folder.
- 1OTel tracing
Do — Wrap every agent step in an OTel span with input/output attributes. Export to console.
Expected artifact — Console shows nested spans for each /ask call with non-empty attributes.
Run free: - 2Budget guard
Do — Implement a per-request USD budget. Cap one request at $0.001 and confirm it raises.
Expected artifact — RuntimeError: budget exceeded; cost logged.
Run free: - 3Load test
Do — Use hey or k6 to send 100 RPS for 30s. Record p50/p95 and error rate.
Expected artifact — load.md with the latency table and a 2-line tuning recommendation.
Run free:
Authoritative sources
Independent primary sources used to check and corroborate the guidance on this page.
- NIST National Initiative for Cybersecurity Education (NICE)
US national framework for cybersecurity work roles and competencies.
- Financial Action Task Force (FATF)
Global AML/CFT standards referenced by financial-crime curricula.
- FBI Internet Crime Complaint Center — Annual Reports
Primary loss and typology data used in fraud-investigation training.
- US Federal Trade Commission — Consumer Sentinel Data Book
Official complaint statistics for teaching fraud trend analysis.
