-
Notifications
You must be signed in to change notification settings - Fork 413
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
fix(flask): fix crashes with flask-like frameworks #9555
Conversation
Datadog ReportBranch report: ✅ 0 Failed, 175663 Passed, 1875 Skipped, 10h 12m 15.21s Total duration (31m 26.65s time saved) |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9555 +/- ##
===========================================
- Coverage 75.61% 8.70% -66.92%
===========================================
Files 1336 1349 +13
Lines 125991 125223 -768
===========================================
- Hits 95271 10902 -84369
- Misses 30720 114321 +83601 ☔ View full report in Codecov by Sentry. |
BenchmarksBenchmark execution time: 2024-07-08 16:31:52 Comparing candidate commit 914bec2 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 221 metrics, 9 unstable metrics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised that this code change makes a difference in behavior. Could you add a regression test that proves that it has the intended effect?
Hey @emmettbutler ! Sorry for delays, I just got back around to this PR today.
I added a test. I also had to re-run As for the test itself, ran it locally without the changes to
As shown in the CI runs on this PR, with the fix in place, those errors don't show up. Happy to expand on this test if this isn't what you had in mind! |
## What does this PR do Adds `provide_automatic_options` as an extra named argument to `patched_add_url_rule`. Previously, when using a framework like [`flask-openapi3`](https://pypi.org/project/flask-openapi3/), and running the Hello World example linked using `ddtrace-run`, users would see the following: ``` File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/app.py", line 18, in <module> def get_book(query: BookQuery): File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/scaffold.py", line 182, in decorator self._add_url_rule(rule, view_func=view_func, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/openapi.py", line 411, in _add_url_rule self.add_url_rule(rule, endpoint, view_func, provide_automatic_options, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/ddtrace/contrib/flask/patch.py", line 433, in patched_add_url_rule return _wrap(*args, **kwargs) TypeError: patched_add_url_rule.<locals>._wrap() takes from 1 to 3 positional arguments but 4 were given ``` After this change, this error is no longer present. This is because `flask-openapi3` passes in `provide_automatic_options` as an unnamed argument as the fourth positional argument, but is read on Flask as a keyword arg. ## Testing Added a regression test that instruments a barebones `flask-openapi3` app, and runs Datadog instrumentation on it, asserting no errors. Additionally, this change was verified manually in a running app, for both instrumentation and execution. ## 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 - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] 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: Emmett Butler <723615+emmettbutler@users.noreply.github.com> (cherry picked from commit 558c7c6)
## What does this PR do Adds `provide_automatic_options` as an extra named argument to `patched_add_url_rule`. Previously, when using a framework like [`flask-openapi3`](https://pypi.org/project/flask-openapi3/), and running the Hello World example linked using `ddtrace-run`, users would see the following: ``` File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/app.py", line 18, in <module> def get_book(query: BookQuery): File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/scaffold.py", line 182, in decorator self._add_url_rule(rule, view_func=view_func, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/openapi.py", line 411, in _add_url_rule self.add_url_rule(rule, endpoint, view_func, provide_automatic_options, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/ddtrace/contrib/flask/patch.py", line 433, in patched_add_url_rule return _wrap(*args, **kwargs) TypeError: patched_add_url_rule.<locals>._wrap() takes from 1 to 3 positional arguments but 4 were given ``` After this change, this error is no longer present. This is because `flask-openapi3` passes in `provide_automatic_options` as an unnamed argument as the fourth positional argument, but is read on Flask as a keyword arg. ## Testing Added a regression test that instruments a barebones `flask-openapi3` app, and runs Datadog instrumentation on it, asserting no errors. Additionally, this change was verified manually in a running app, for both instrumentation and execution. ## 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 - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] 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: Emmett Butler <723615+emmettbutler@users.noreply.github.com> (cherry picked from commit 558c7c6)
## What does this PR do Adds `provide_automatic_options` as an extra named argument to `patched_add_url_rule`. Previously, when using a framework like [`flask-openapi3`](https://pypi.org/project/flask-openapi3/), and running the Hello World example linked using `ddtrace-run`, users would see the following: ``` File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/app.py", line 18, in <module> def get_book(query: BookQuery): File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/scaffold.py", line 182, in decorator self._add_url_rule(rule, view_func=view_func, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/openapi.py", line 411, in _add_url_rule self.add_url_rule(rule, endpoint, view_func, provide_automatic_options, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/ddtrace/contrib/flask/patch.py", line 433, in patched_add_url_rule return _wrap(*args, **kwargs) TypeError: patched_add_url_rule.<locals>._wrap() takes from 1 to 3 positional arguments but 4 were given ``` After this change, this error is no longer present. This is because `flask-openapi3` passes in `provide_automatic_options` as an unnamed argument as the fourth positional argument, but is read on Flask as a keyword arg. ## Testing Added a regression test that instruments a barebones `flask-openapi3` app, and runs Datadog instrumentation on it, asserting no errors. Additionally, this change was verified manually in a running app, for both instrumentation and execution. ## 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 - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] 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: Emmett Butler <723615+emmettbutler@users.noreply.github.com> (cherry picked from commit 558c7c6)
) Backport 558c7c6 from #9555 to 2.9. ## What does this PR do Adds `provide_automatic_options` as an extra named argument to `patched_add_url_rule`. Previously, when using a framework like [`flask-openapi3`](https://pypi.org/project/flask-openapi3/), and running the Hello World example linked using `ddtrace-run`, users would see the following: ``` File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/app.py", line 18, in <module> def get_book(query: BookQuery): File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/scaffold.py", line 182, in decorator self._add_url_rule(rule, view_func=view_func, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/openapi.py", line 411, in _add_url_rule self.add_url_rule(rule, endpoint, view_func, provide_automatic_options, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/ddtrace/contrib/flask/patch.py", line 433, in patched_add_url_rule return _wrap(*args, **kwargs) TypeError: patched_add_url_rule.<locals>._wrap() takes from 1 to 3 positional arguments but 4 were given ``` After this change, this error is no longer present. This is because `flask-openapi3` passes in `provide_automatic_options` as an unnamed argument as the fourth positional argument, but is read on Flask as a keyword arg. ## Testing Added a regression test that instruments a barebones `flask-openapi3` app, and runs Datadog instrumentation on it, asserting no errors. Additionally, this change was verified manually in a running app, for both instrumentation and execution. ## 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 - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] 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: Sam Brenner <106700075+sabrenner@users.noreply.github.com>
) Backport 558c7c6 from #9555 to 2.8. ## What does this PR do Adds `provide_automatic_options` as an extra named argument to `patched_add_url_rule`. Previously, when using a framework like [`flask-openapi3`](https://pypi.org/project/flask-openapi3/), and running the Hello World example linked using `ddtrace-run`, users would see the following: ``` File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/app.py", line 18, in <module> def get_book(query: BookQuery): File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/scaffold.py", line 182, in decorator self._add_url_rule(rule, view_func=view_func, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/openapi.py", line 411, in _add_url_rule self.add_url_rule(rule, endpoint, view_func, provide_automatic_options, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/ddtrace/contrib/flask/patch.py", line 433, in patched_add_url_rule return _wrap(*args, **kwargs) TypeError: patched_add_url_rule.<locals>._wrap() takes from 1 to 3 positional arguments but 4 were given ``` After this change, this error is no longer present. This is because `flask-openapi3` passes in `provide_automatic_options` as an unnamed argument as the fourth positional argument, but is read on Flask as a keyword arg. ## Testing Added a regression test that instruments a barebones `flask-openapi3` app, and runs Datadog instrumentation on it, asserting no errors. Additionally, this change was verified manually in a running app, for both instrumentation and execution. ## 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 - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] 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: Sam Brenner <106700075+sabrenner@users.noreply.github.com>
…9755) Backport 558c7c6 from #9555 to 2.10. ## What does this PR do Adds `provide_automatic_options` as an extra named argument to `patched_add_url_rule`. Previously, when using a framework like [`flask-openapi3`](https://pypi.org/project/flask-openapi3/), and running the Hello World example linked using `ddtrace-run`, users would see the following: ``` File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/app.py", line 18, in <module> def get_book(query: BookQuery): File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/scaffold.py", line 182, in decorator self._add_url_rule(rule, view_func=view_func, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/flask_openapi3/openapi.py", line 411, in _add_url_rule self.add_url_rule(rule, endpoint, view_func, provide_automatic_options, **options) File "/Users/sam.brenner/Development/ml-obs/sandboxes/support/.venv/lib/python3.10/site-packages/ddtrace/contrib/flask/patch.py", line 433, in patched_add_url_rule return _wrap(*args, **kwargs) TypeError: patched_add_url_rule.<locals>._wrap() takes from 1 to 3 positional arguments but 4 were given ``` After this change, this error is no longer present. This is because `flask-openapi3` passes in `provide_automatic_options` as an unnamed argument as the fourth positional argument, but is read on Flask as a keyword arg. ## Testing Added a regression test that instruments a barebones `flask-openapi3` app, and runs Datadog instrumentation on it, asserting no errors. Additionally, this change was verified manually in a running app, for both instrumentation and execution. ## 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 - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] 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: Sam Brenner <106700075+sabrenner@users.noreply.github.com>
What does this PR do
Adds
provide_automatic_options
as an extra named argument topatched_add_url_rule
. Previously, when using a framework likeflask-openapi3
, and running the Hello World example linked usingddtrace-run
, users would see the following:After this change, this error is no longer present.
This is because
flask-openapi3
passes inprovide_automatic_options
as an unnamed argument as the fourth positional argument, but is read on Flask as a keyword arg.Testing
Added a regression test that instruments a barebones
flask-openapi3
app, and runs Datadog instrumentation on it, asserting no errors. Additionally, this change was verified manually in a running app, for both instrumentation and execution.Checklist
changelog/no-changelog
is set@DataDog/apm-tees
.Reviewer Checklist