Principle:Wandb Weave Patch Reversal
| Knowledge Sources | |
|---|---|
| Domains | Instrumentation, Resource_Management |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
A cleanup mechanism that restores original library methods by undoing all applied monkey-patches.
Description
Patch Reversal restores the original, unpatched versions of provider SDK methods. This is essential for testing (to prevent test interference), cleanup, and scenarios where tracing should be selectively disabled. The reversal is hierarchical: MultiPatcher iterates all sub-patchers, and each SymbolPatcher restores its stored original value.
Usage
Use this principle when you need to stop tracing for specific integrations, during test teardown, or when switching between tracing configurations.
Theoretical Basis
Patch reversal follows the memento pattern:
- Save: When patching, store the original method value.
- Replace: Install the traced wrapper.
- Restore: On undo, use setattr to restore the saved original value.
The hierarchical structure (MultiPatcher containing SymbolPatchers) ensures that all patches for a provider are reversed atomically.