Skip to content
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

chore(ci_visibility): fix line numbers in Python 3.10 bytecode [backport #10454 to 2.12] #10528

Closed
wants to merge 1 commit into from

Conversation

vitor-de-araujo
Copy link
Contributor

Backport 4bd2998 from #10454 to 2.12.

The line number information in Python 3.10 bytecode is encoded using pairs of (offset_delta, line_number_delta) bytes (more info here). When the line number delta exceeds the limits of a signed byte, this is encoded by using an offset_delta of 0, which was not handled correctly by our instrumentation. This PR fixes that.

This solves an issue where two consecutive opcode instructions with a line gap greater than 127 would be assigned incorrect line numbers, which was triggering an error in dogweb CI.

Testing strategy

This PR was tested in two ways:

  • Verifying that the error in the dogweb CI is solved by the change.
  • Comparing the output of dis.dis() on the bytecode of the offending function in dogweb (1) before instrumentation, (2) after instrumentation before this fix, and (3) after instrumentation with this fix. After the fix, the line numbers for (1) and (3) match, whereas those for (2) don't.

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

The line number information in Python 3.10 bytecode is encoded using
pairs of (offset_delta, line_number_delta) bytes ([more info
here](https://github.com/python/cpython/blob/3.10/Objects/lnotab_notes.txt)).
When the line number delta exceeds the limits of a signed byte, this is
encoded by using an offset_delta of 0, which was not handled correctly
by our instrumentation. This PR fixes that.

This solves an issue where two consecutive opcode instructions with a
line gap greater than 127 would be assigned incorrect line numbers,
which was triggering an error in dogweb CI.

## Testing strategy

This PR was tested in two ways:

- Verifying that the error in the dogweb CI is solved by the change.
- Comparing the output of `dis.dis()` on the bytecode of the offending
function in dogweb (1) before instrumentation, (2) after instrumentation
before this fix, and (3) after instrumentation with this fix. After the
fix, the line numbers for (1) and (3) match, whereas those for (2)
don't.

## Checklist
- [x] 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](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] 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](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
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](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)

(cherry picked from commit 4bd2998)
@vitor-de-araujo vitor-de-araujo requested review from a team as code owners September 5, 2024 15:16
@vitor-de-araujo vitor-de-araujo added the changelog/no-changelog A changelog entry is not required for this PR. label Sep 5, 2024
@vitor-de-araujo vitor-de-araujo self-assigned this Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog A changelog entry is not required for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant