Open source

Graham Dumpleton's new Python package wrapture does testing and OpenTelemetry tracing from the same bindings

September 11, 2026 at 7:20 AM PT

GitHub social card for the GrahamDumpleton/wrapture repository

Image: GitHub

Why it mattersA Python team can point one library at a call site and get both mock-style test assertions and OpenTelemetry spans, instead of maintaining a mock in the test suite and a separate instrumentation library in production.

Graham Dumpleton, the author of the widely used wrapt monkey-patching library and the original author of the New Relic Python agent, released a new Python package called wrapture on 31 August, with the first announcement post on his blog. Ten follow-up tutorials have gone out almost daily since then. Simon Willison flagged the release on 11 September, saying he was "not sure why I've seen so little buzz about it" and calling wrapture "one of those Swiss Army Knife packages that, once mastered, will provide value against all sorts of problems for years to come".

The name is wrapt plus capture. Dumpleton writes that testing and tracing "look like different problems, but from where I sat they wanted the same thing". unittest.mock answers every method call, verifies nothing on its own, and records a flat list of calls with no return values and no sense of what called what. Instrumentation libraries used for tracing, by contrast, record real calls but do not let a test assert against them. Wrapture is his attempt to serve both jobs from one set of bindings.

Wrap instead of replace

Every wrapture binding names a location in code, a method of a class or a function in a module, and installs a wrapt wrapper around the real callable when it is applied. Unless a test tells it otherwise, the wrapper is transparent: the real code runs, and wrapture sits in a position to watch the call, change it, or answer it instead of the real function. That means a test can assert against the actual calls a component makes, including internal ones between its own methods, without swapping the component out for a fabrication.

The same bindings can produce a timeline of calls with return values, arranged as a tree that follows the call graph rather than the flat list unittest.mock produces. Dumpleton has published separate tutorials on phased behaviour across calls, on recording calls for later inspection, and on patching attributes, dictionaries, and generators as well as callables.

Zero-code tracing and an OpenTelemetry export

Wrapture can also be configured from a separate TOML file, without editing the Python code it observes. Dumpleton's tutorial titled "Zero-code tracing with wrapture" describes turning tracing on for a live program from an external file, and the "OpenTelemetry export in wrapture" post shows how to send those traces into an OpenTelemetry collector. A companion package called wrapture-instrumentation ships pre-written bindings for aiohttp, Django, FastAPI, Flask, gRPC, httpx, requests, SQLAlchemy, SQLite3, Starlette, uvicorn, and about a dozen more standard-library and framework entry points.

The package is still alpha, released under BSD 2-Clause, and the GitHub repository holds 30 stars at the time Willison's post went out. In the introduction post Dumpleton says the code was "written by an AI under my direction", which is worth noting on a site whose whole pitch is that AI-written code needs an eval suite before it ships: an author with two decades of experience in exactly this problem area is the eval suite here.

For a Python team, the practical decision is whether to keep unittest.mock and an OpenTelemetry instrumentation library as two separate dependencies, or move both jobs into one library whose author has thought about wrapping Python for twenty years. Alpha software is alpha software, but the ceiling on this design is high, and Willison flagging it is the reason it will now get read.

Source

Simon Willison's note, Don't sleep on wrapture, pointing at Graham Dumpleton's Introducing wrapture and the tutorials that followed. The code is at GrahamDumpleton/wrapture.

Source: Simon Willison's Weblog

This item was written by an AI system from the linked source. Reveneau is responsible for what it publishes.

More from AI News

Rome open-sources an agentic OS that stores agent work as git-tracked actions and apps

Rome AI Lab has open-sourced Rome, an MIT-licensed agent runtime that turns every proven agent workflow into a git-tracked action, skill, or purpose-built app the next agent can call.

Source: GitHubOpen source

Reverify pairs an AI model with a pure-Python RE toolkit and marks every claim VERIFIED or REFUTED against the actual bytes

A new open-source RE toolkit, reverify, uses deterministic parsers and emulators as the judge for AI-proposed hypotheses about a binary, and has 662 stars in the three days since it was created.

Source: GitHubOpen source

Mezmo open-sourced Aura, an SRE agent platform where the whole agent definition sits in a reviewable TOML file

The observability company Mezmo released Aura, an Apache-licensed Rust agent for investigating and fixing production incidents whose entire agent system is defined in TOML, with 267 stars on the repository.

Source: Hacker NewsOpen source