Runtime hooks and monkey patching
In Python, unlike in Java, where a single archive contains everything that's needed to support auto-instrumentation, the implementation relies on several separate components that must be discussed to help us fully understand how auto-instrumentation works.
Instrumenting libraries
Instrumentation libraries in Python rely on one of two mechanisms to instrument third-party libraries:
- Event hooks are exposed by the libraries being instrumented, allowing the instrumenting libraries to register and produce telemetry as events occur.
- Any intercepting calls to libraries are instrumented and are replaced at runtime via a technique known as monkey patching (https://en.wikipedia.org/wiki/Monkey_patch). The instrumenting library receives the original call, produces telemetry data, and then calls the underlying library.
Monkey patching is like bytecode injection in that the applications make calls to libraries without suspecting that...