Skip to content

fix(tracing): ensure tracer.wrap preserves decorated function’s type #13906

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 4 commits into from
Jul 12, 2025

Conversation

zemek
Copy link
Contributor

@zemek zemek commented Jul 7, 2025

This change reverts a regression introduced in #13480 where using @tracer.wrap() causes type checkers to infer the return type of decorated functions as Any instead of the actual return type.

Addresses #13637

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

@brettlangdon
Copy link
Member

brettlangdon commented Jul 8, 2025

@zemek thanks for this contribution. We have a requirement that all contribution commits are signed, would you be able to update this PR to have signed commits?

If not, I'd be more than happy to make a clone PR and squash/sign the commits with my gpg key, and I can help make sure you are still listed as co-authored on the change.

@zemek
Copy link
Contributor Author

zemek commented Jul 8, 2025

@brettlangdon I believe I've signed the commits now, let me know if there's anything else I need to do. Thanks!

@brettlangdon brettlangdon enabled auto-merge (squash) July 8, 2025 17:22
@brettlangdon
Copy link
Member

Now there are some typing issues:

ddtrace/_trace/tracer.py:785: error: Incompatible return value type (got "_Wrapped[[VarArg(Any), KwArg(Any)], Any, [VarArg(Any), KwArg(Any)], Any]", expected "AnyCallable")  [return-value]
ddtrace/_trace/tracer.py:803: error: Incompatible return value type (got "_Wrapped[[VarArg(Any), KwArg(Any)], Any, [VarArg(Any), KwArg(Any)], Any]", expected "AnyCallable")  [return-value]

You can run these checks locally with:

./scripts/ddtest hatch run lint:checks
./scripts/ddtest hatch run lint:typing

auto-merge was automatically disabled July 8, 2025 18:19

Head branch was pushed to by a user without write access

@zemek
Copy link
Contributor Author

zemek commented Jul 8, 2025

Now there are some typing issues:

ddtrace/_trace/tracer.py:785: error: Incompatible return value type (got "_Wrapped[[VarArg(Any), KwArg(Any)], Any, [VarArg(Any), KwArg(Any)], Any]", expected "AnyCallable")  [return-value]
ddtrace/_trace/tracer.py:803: error: Incompatible return value type (got "_Wrapped[[VarArg(Any), KwArg(Any)], Any, [VarArg(Any), KwArg(Any)], Any]", expected "AnyCallable")  [return-value]

You can run these checks locally with:

./scripts/ddtest hatch run lint:checks
./scripts/ddtest hatch run lint:typing

Ok it looks like both

./scripts/ddtest hatch run lint:checks
./scripts/ddtest hatch run lint:typing

succeed now (other than some errors that codespell is reporting in unrelated files)

@zemek
Copy link
Contributor Author

zemek commented Jul 10, 2025

@brettlangdon it seems like the tests are failing that the DD_API_KEY is not set, but I'm not sure why my change would cause that?

Actually it looks like all ${{ secrets.* }} are just being rendered as empty string

@brettlangdon
Copy link
Member

@brettlangdon it seems like the tests are failing that the DD_API_KEY is not set, but I'm not sure why my change would cause that?

Actually it looks like all ${{ secrets.* }} are just being rendered as empty string

Hey, sorry for the delay getting back to reviewing this PR. I'll try to set aside some time tomorrow to review again.

I need to do some magic to get CI to run your changes, since we don't allow access to CI secrets for non-employees.

@zemek
Copy link
Contributor Author

zemek commented Jul 11, 2025

@brettlangdon I see some tests failed in system-tests are those known to be flaky? I saw that some other PR's had the same errors:
https://github.com/DataDog/dd-trace-py/actions/runs/16221145773
https://github.com/DataDog/dd-trace-py/actions/runs/16210874121
https://github.com/DataDog/dd-trace-py/actions/runs/16205264531
https://github.com/DataDog/dd-trace-py/actions/runs/16204494733

(just want to make sure this wasn't due to my change)

@brettlangdon
Copy link
Member

@brettlangdon I see some tests failed in system-tests are those known to be flaky? I saw that some other PR's had the same errors: https://github.com/DataDog/dd-trace-py/actions/runs/16221145773 https://github.com/DataDog/dd-trace-py/actions/runs/16210874121 https://github.com/DataDog/dd-trace-py/actions/runs/16205264531 https://github.com/DataDog/dd-trace-py/actions/runs/16204494733

(just want to make sure this wasn't due to my change)

I got it from here, I'll let you know if any changes are needed, these appear to be flaky jobs.

@brettlangdon brettlangdon merged commit 65c54f6 into DataDog:main Jul 12, 2025
823 checks passed
github-actions bot pushed a commit that referenced this pull request Jul 12, 2025
…13906)

This change reverts a regression introduced in
#13480 where using
`@tracer.wrap()` causes type checkers to infer the return type of
decorated functions as `Any` instead of the actual return type.

Addresses #13637

## 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)

---------

Co-authored-by: Rachel Yang <rachel.yang@datadoghq.com>
Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
(cherry picked from commit 65c54f6)
brettlangdon added a commit that referenced this pull request Jul 12, 2025
…13906)

This change reverts a regression introduced in
`@tracer.wrap()` causes type checkers to infer the return type of
decorated functions as `Any` instead of the actual return type.

Addresses #13637

- [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))

- [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)

---------

Co-authored-by: Joseph Zemek <jazemek@gmail.com>
Co-authored-by: Rachel Yang <rachel.yang@datadoghq.com>
Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
taegyunkim pushed a commit that referenced this pull request Jul 14, 2025
…13906)

This change reverts a regression introduced in
#13480 where using
`@tracer.wrap()` causes type checkers to infer the return type of
decorated functions as `Any` instead of the actual return type.

Addresses #13637

## 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)

---------

Co-authored-by: Rachel Yang <rachel.yang@datadoghq.com>
Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants