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

Optimize response body length reporting in OkHttp instrumentation #1790

Conversation

0xnm
Copy link
Member

@0xnm 0xnm commented Dec 27, 2023

What does this PR do?

This PR optimizes the way we are reporting response body length in OkHttp instrumentation.

We first try to get content length from response body as-is, and if it didn't work, we try to call peekBody. The explanation to that is related to the way OkHttp works: the following doc states, that OkHttp will remove Content-Length header (and make contentLength() return -1) if transparent compression is used. This means that if body.contentLength returns positive value, then we are good already, and if it is not, we may try to call peekBody which will apply decompression and load a decompressed body in memory.

Another benefit is that now we can report body length more than 1MB, because peekBody was limited by 1MB and if there is no need to call it, we may report full body length.

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@0xnm 0xnm requested review from a team as code owners December 27, 2023 10:16
@0xnm 0xnm force-pushed the nogorodnikov/optimize-body-length-reporting-in-okhttp-instrumentation branch from c0cce81 to c42c0c2 Compare December 27, 2023 10:35
@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2023

Codecov Report

Merging #1790 (c42c0c2) into develop (9eefcc4) will decrease coverage by 0.21%.
The diff coverage is 83.33%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1790      +/-   ##
===========================================
- Coverage    83.64%   83.43%   -0.21%     
===========================================
  Files          466      466              
  Lines        16368    16347      -21     
  Branches      2451     2449       -2     
===========================================
- Hits         13691    13639      -52     
- Misses        2023     2042      +19     
- Partials       654      666      +12     
Files Coverage Δ
...n/com/datadog/android/okhttp/DatadogInterceptor.kt 72.92% <83.33%> (+0.38%) ⬆️

... and 23 files with indirect coverage changes

@0xnm 0xnm merged commit 34ff209 into develop Dec 28, 2023
5 checks passed
@0xnm 0xnm deleted the nogorodnikov/optimize-body-length-reporting-in-okhttp-instrumentation branch December 28, 2023 08:35
@xgouchet xgouchet added this to the 2.5.0 milestone Feb 19, 2024
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.

4 participants