Skip to content

Commit

Permalink
chore(internal): bytecode wrapping context (#9222)
Browse files Browse the repository at this point in the history
We introduce a new mechanism of wrapping functions via a special context
manager that is capable of capturing return values as well. The goal is
to allow observability into the called functions, to have access to
local variables on exit. This approach has the extra benefit of not
introducing any extra frames in the call stack of the wrapped function.

## Checklist

- [x] Change(s) are motivated and described in the PR description
- [x] Testing strategy is described if automated tests are not included
in the PR
- [x] Risks are described (performance impact, potential for breakage,
maintainability)
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed or label `changelog/no-changelog` is set
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/))
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
- [x] If this PR changes the public interface, I've notified
`@DataDog/apm-tees`.

## Reviewer Checklist

- [ ] Title is accurate
- [ ] All changes are related to the pull request's stated goal
- [ ] Description motivates each change
- [ ] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [ ] Testing strategy adequately addresses listed risks
- [ ] Change is maintainable (easy to change, telemetry, documentation)
- [ ] Release note makes sense to a user of the library
- [ ] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [ ] Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
P403n1x87 committed May 21, 2024
1 parent 9e9c81a commit c5cf56f
Show file tree
Hide file tree
Showing 3 changed files with 995 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ddtrace/internal/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,6 @@ def dis(self) -> None:

def __iter__(self) -> t.Iterator[bc.Instr]:
return iter(self._instrs)

def __len__(self) -> int:
return len(self._instrs)

0 comments on commit c5cf56f

Please sign in to comment.