-
Notifications
You must be signed in to change notification settings - Fork 417
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(asgi, starlette, fastapi): exclude background task durations from web requests #3799
fix(asgi, starlette, fastapi): exclude background task durations from web requests #3799
Conversation
@wantsui this pull request is now in conflict 😩 |
2bf1234
to
157af78
Compare
…e, and fastapi. Update the releases for the change.
157af78
to
423ae28
Compare
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.
Nice fix!
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.
This looks great! I just have a nitpick/question or two and then should be ready!
Codecov Report
@@ Coverage Diff @@
## 1.x #3799 +/- ##
==========================================
+ Coverage 78.00% 78.11% +0.10%
==========================================
Files 672 674 +2
Lines 51777 52098 +321
==========================================
+ Hits 40390 40695 +305
- Misses 11387 11403 +16
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
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.
looks great.
I am worried about a case where we might not finish the request span.
I also think if we can add test cases when more_data
is present in the http response body events would be good as well.
…finished with False. Rename tests for clarity.
update with 1.x changes
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.
Nice tests for more_body
! Looks great!
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.
minor nit pick over how you are asserting that the span was not finished, but otherwise everything looks great
Co-authored-by: Brett Langdon <me@brett.is>
Co-authored-by: Brett Langdon <me@brett.is>
Co-authored-by: Brett Langdon <me@brett.is>
@Mergifyio backport 1.2 |
… web requests (#3799) Following up on #3023, currently libraries traced via the `asgi` integration, such as`fastapi.request` and `starlette.request` spans include the duration of background tasks. This PR updates the asgi middleware code so that spans end earlier by excluding background tasks to better represent the web requests response times. **Current Behavior** $$\begin{align}duration = {http response time} + {background tasks time}\end{align}$$ **What it looks like with the PR** $$\begin{align}duration = {http response time}\end{align}$$ **Example:** An application return a "hello world!" to the user in $2 milliseconds$, but the events that happen in the background lasts another $8 seconds$. With this PR, the span will report a duration of $2 milliseconds$, instead of $2 milliseconds + 8 seconds$. Fixes #3023 Also fixes this failing test: https://app.circleci.com/pipelines/github/DataDog/dd-trace-py/18150/workflows/24caa985-5805-4bff-a4eb-5b143f24a2fb/jobs/1233079 ## Checklist - [ ] Library documentation is updated. - [ ] [Corp site](https://github.com/DataDog/documentation/) documentation is updated (link to the PR). ## Reviewer Checklist - [ ] Title is accurate. - [ ] Description motivates each change. - [ ] No unnecessary changes were introduced in this PR. - [ ] PR cannot be broken up into smaller PRs. - [ ] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Tests provided or description of manual testing performed is included in the code or PR. - [ ] Release note has been added for fixes and features, or else `changelog/no-changelog` label added. - [ ] All relevant GitHub issues are correctly linked. - [ ] Backports are identified and tagged with Mergifyio. - [ ] Add to milestone. (cherry picked from commit 5b97489)
✅ Backports have been created
|
… web requests (backport #3799) (#3840) This is an automatic backport of pull request #3799 done by [Mergify](https://mergify.com). --- <details> <summary>Mergify commands and options</summary> <br /> More conditions and actions can be found in the [documentation](https://docs.mergify.com/). You can also trigger Mergify actions by commenting on this pull request: - `@Mergifyio refresh` will re-evaluate the rules - `@Mergifyio rebase` will rebase this PR on its base branch - `@Mergifyio update` will merge the base branch into this PR - `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch Additionally, on Mergify [dashboard](https://dashboard.mergify.com/) you can: - look at your merge queues - generate the Mergify configuration with the config editor. Finally, you can contact us on https://mergify.com </details>
Following up on #3023, currently libraries traced via the
asgi
integration, such asfastapi.request
andstarlette.request
spans include the duration of background tasks. This PR updates the asgi middleware code so that spans end earlier by excluding background tasks to better represent the web requests response times.Current Behavior
$$\begin{align}duration = {http response time} + {background tasks time}\end{align}$$
What it looks like with the PR
$$\begin{align}duration = {http response time}\end{align}$$
Example: An application return a "hello world!" to the user in$2 milliseconds$ , but the events that happen in the background lasts another $8 seconds$ .
With this PR, the span will report a duration of$2 milliseconds$ , instead of $2 milliseconds + 8 seconds$ .
Fixes #3023
Also fixes this failing test: https://app.circleci.com/pipelines/github/DataDog/dd-trace-py/18150/workflows/24caa985-5805-4bff-a4eb-5b143f24a2fb/jobs/1233079
Checklist
Reviewer Checklist
changelog/no-changelog
label added.