Quickstart: observe an existing consumer
If you already have a consumer running (any broker, any framework), you don't need to rewrite it to get visibility. Wrap each delivery in an observation and Observatory gets the outcome, the timing, and the trace lineage, and you get dashboard control back.
Before you start
You'll need an API key scoped to telemetry. Any admin can create one under Organization settings → API Keys. Keep it secret and treat it like a password.
- 1Install the SDKpip install "pymidil[auth]"
- 2Create a ConsumerObserverGive it your Observatory URL, your API key, a name for this consumer (this is what shows up, and what you'll control, in the dashboard), and a label for the broker it reads from:from pymidil.event.observability import ConsumerObserverobserve = ConsumerObserver(observatory_url="https://api.midil.io",api_key="mo_your_api_key",consumer="orders-worker",broker="kafka", # any broker works, it's just a label)
- 3Wrap each deliveryDrop the observation around the part of your loop that handles one message. Everything inside runs exactly as it did before:The event type string (async for record in your_existing_consumer: # your existing loopasync with observe(record.key, "OrderPlaced", headers=record.headers):await handle_order(record) # your code, untouched
"OrderPlaced"above) is whatever name you want that kind of event to show up as in the dashboard. - 4Honor dashboard control (optional, recommended)Check control state before pulling the next message, so pausing/throttling a consumer from the dashboard actually does something:See the [Consumer control](/sdks/python/guides/consumer-control) guide for throttling and draining too.if not (await observe.control.get()).state.should_pull:continue # paused or draining from the dashboard
- 5Check the dashboardOpen Overview. Your first observed event should appear within moments.
ProducerObserver is the emit-side counterpart, for wrapping a service that publishes events rather
than consumes them. Same idea, wrapped around your send call instead of your handler.