Skip to content

fix: iteration block hook injection [backport 3.9] #13802

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

Merged
merged 1 commit into from
Jul 1, 2025

Conversation

github-actions[bot]
Copy link
Contributor

Backport d7b62d5 from #13772 to 3.9.

We fix an issue with the instrumentation of the beginning of iteration blocks (e.g. for loops) whereby instrumenting the end might cause unexpected behaviour when the modified function is invoked. This is due to the bytecode VM not liking any bytecode interposed before the instruction that ends the iteration block (e.g. END_FOR). This also solves the problem of double-calls of the instrumented hook when hitting the beginning of such blocks.

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, 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

@github-actions github-actions bot added the Dynamic Instrumentation Dynamic Instrumentation/Live Debugger label Jun 27, 2025
@github-actions github-actions bot requested review from a team as code owners June 27, 2025 15:21
@github-actions github-actions bot added the Dynamic Instrumentation Dynamic Instrumentation/Live Debugger label Jun 27, 2025
@github-actions github-actions bot requested review from brettlangdon and gnufede June 27, 2025 15:21
@P403n1x87 P403n1x87 closed this Jun 27, 2025
@P403n1x87 P403n1x87 reopened this Jun 27, 2025
@P403n1x87 P403n1x87 enabled auto-merge (squash) June 27, 2025 15:23
Copy link
Contributor Author

CODEOWNERS have been resolved as:

releasenotes/notes/fix-iteration-block-injection-af354b7004554dfd.yaml  @DataDog/apm-python
ddtrace/internal/bytecode_injection/__init__.py                         @DataDog/apm-core-python
tests/internal/bytecode_injection/test_injection.py                     @DataDog/apm-core-python

Copy link
Contributor Author

github-actions bot commented Jun 27, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 275 ± 3 ms.

The average import time from base is: 276 ± 2 ms.

The import time difference between this PR and base is: -1.7 ± 0.1 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 1.951 ms (0.71%)
ddtrace.bootstrap.sitecustomize 1.274 ms (0.46%)
ddtrace.bootstrap.preload 1.274 ms (0.46%)
ddtrace.internal.remoteconfig.client 0.627 ms (0.23%)
ddtrace 0.677 ms (0.25%)
ddtrace.internal._unpatched 0.031 ms (0.01%)
json 0.031 ms (0.01%)
json.decoder 0.031 ms (0.01%)
re 0.031 ms (0.01%)
enum 0.031 ms (0.01%)
types 0.031 ms (0.01%)

@pr-commenter
Copy link

pr-commenter bot commented Jun 27, 2025

Benchmarks

Benchmark execution time: 2025-06-30 14:09:03

Comparing candidate commit d883fbb in PR branch backport-13772-to-3.9 with baseline commit e0e451c in branch 3.9.

Found 0 performance improvements and 2 performance regressions! Performance is the same for 528 metrics, 2 unstable metrics.

scenario:iastaspects-format_map_aspect

  • 🟥 execution_time [+515.681ns; +578.143ns] or [+15.816%; +17.731%]

scenario:iastaspectsospath-ospathsplitdrive_aspect

  • 🟥 execution_time [+516.546ns; +582.514ns] or [+13.949%; +15.730%]

@emmettbutler emmettbutler disabled auto-merge June 27, 2025 17:33
@brettlangdon brettlangdon force-pushed the backport-13772-to-3.9 branch from c0cc765 to d883fbb Compare June 30, 2025 13:19
@brettlangdon brettlangdon enabled auto-merge (squash) June 30, 2025 13:19
auto-merge was automatically disabled July 1, 2025 12:15

Pull request was closed

@brettlangdon brettlangdon reopened this Jul 1, 2025
@brettlangdon brettlangdon enabled auto-merge (squash) July 1, 2025 12:16
@brettlangdon brettlangdon merged commit ee1aabe into 3.9 Jul 1, 2025
872 checks passed
@brettlangdon brettlangdon deleted the backport-13772-to-3.9 branch July 1, 2025 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dynamic Instrumentation Dynamic Instrumentation/Live Debugger
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants