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

fix(asgi, starlette, fastapi): exclude background task durations from web requests (backport #3799) #3840

Merged
merged 1 commit into from
Jun 21, 2022

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Jun 21, 2022

This is an automatic backport of pull request #3799 done by Mergify.


Mergify commands and options

More conditions and actions can be found in the documentation.

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 you can:

  • look at your merge queues
  • generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com

… 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)
@codecov-commenter
Copy link

Codecov Report

Merging #3840 (1723ac4) into 1.2 (97e020a) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              1.2    #3840      +/-   ##
==========================================
+ Coverage   77.48%   77.51%   +0.03%     
==========================================
  Files         667      667              
  Lines       51417    51500      +83     
==========================================
+ Hits        39838    39921      +83     
  Misses      11579    11579              
Impacted Files Coverage Δ
ddtrace/contrib/asgi/middleware.py 95.37% <100.00%> (+0.13%) ⬆️
tests/contrib/asgi/test_asgi.py 100.00% <100.00%> (ø)
tests/contrib/fastapi/app.py 93.33% <100.00%> (+0.65%) ⬆️
tests/contrib/fastapi/test_fastapi.py 100.00% <100.00%> (ø)
tests/contrib/starlette/app.py 95.06% <100.00%> (+0.54%) ⬆️
tests/contrib/starlette/test_starlette.py 100.00% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@mergify mergify bot merged commit 936a819 into 1.2 Jun 21, 2022
@mergify mergify bot deleted the mergify/bp/1.2/pr-3799 branch June 21, 2022 18:26
@wantsui wantsui added this to the v1.2.1 milestone Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants