Skip to content

fix: generator wrapping with Python 3.10 [backport 2.21] #13840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.21
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ddtrace/internal/wrapping/context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import ABC
from contextvars import ContextVar
from inspect import iscoroutinefunction
from inspect import isgeneratorfunction
import sys
from types import FrameType
from types import FunctionType
Expand Down Expand Up @@ -673,9 +674,9 @@ def wrap(self) -> None:
pass
i += 1

# Search for the GEN_START instruction
# Search for the GEN_START instruction, which needs to stay on top.
i = 0
if sys.version_info >= (3, 10) and iscoroutinefunction(f):
if sys.version_info >= (3, 10) and (iscoroutinefunction(f) or isgeneratorfunction(f)):
for i, instr in enumerate(bc, 1):
try:
if instr.name == "GEN_START":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
dynamic instrumentation: fixed an issue with the instrumentation of
generators with Python 3.10.
Loading