Skip to content

RUM-648 Add request id in okhttp request#2126

Merged
xgouchet merged 4 commits into
developfrom
xgouchet/RUM-648/okhttp_request_id
Jul 19, 2024
Merged

RUM-648 Add request id in okhttp request#2126
xgouchet merged 4 commits into
developfrom
xgouchet/RUM-648/okhttp_request_id

Conversation

@xgouchet

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR adds a better way to track OkHttp requests as resources avoiding key collisions. Our keys used to only take into account the url, now we generate a UUID attached to the request to have a more accurate resource representation.

@xgouchet xgouchet requested review from a team as code owners July 17, 2024 15:35
)
fun startResource(
key: String,
key: Any,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we need to keep Any type here? can we just use the new class ResourceId instead?

Comment on lines +99 to +103
DEPRECATED fun startResource(Any, String, String, Map<String, Any?> = emptyMap())
fun startResource(Any, RumResourceMethod, String, Map<String, Any?> = emptyMap())
fun stopResource(Any, Int?, Long?, RumResourceKind, Map<String, Any?>)
fun stopResourceWithError(Any, Int?, String, RumErrorSource, Throwable, Map<String, Any?> = emptyMap())
fun stopResourceWithError(Any, Int?, String, RumErrorSource, String, String?, Map<String, Any?> = emptyMap())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just an idea: while the key for resources is something which is used only as a key, and not some information baggage, making it Any in public API may have some consequences: what if we will have a raise in the number of duplicated keys or a possibility of some memory leak (e.g. some network call instance is passed as a key or Request object, which later maybe be transformed to another Request object by the interceptor chain and in the result request != response.request, leading to hanging resources).

Maybe we can instead add methods like startResource(key: ResourceId, ....), etc. to the AdvancedNetworkRumMonitor and use it as a private API for a while? wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes a lot of sense indeed, I'll do that.

@xgouchet xgouchet requested review from 0xnm and ambushwork July 18, 2024 10:32

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nicely done!

@xgouchet xgouchet force-pushed the xgouchet/RUM-648/okhttp_request_id branch from f95e1a4 to 3ba2e49 Compare July 19, 2024 07:34
@codecov-commenter

codecov-commenter commented Jul 19, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 90.27778% with 7 lines in your changes missing coverage. Please review.

Project coverage is 70.12%. Comparing base (1ce4aa7) to head (3ba2e49).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2126      +/-   ##
===========================================
+ Coverage    70.03%   70.12%   +0.09%     
===========================================
  Files          722      725       +3     
  Lines        26821    26877      +56     
  Branches      4503     4510       +7     
===========================================
+ Hits         18784    18847      +63     
+ Misses        6780     6765      -15     
- Partials      1257     1265       +8     
Files Coverage Δ
.../main/kotlin/com/datadog/android/rum/RumMonitor.kt 28.57% <ø> (ø)
...ndroid/rum/internal/domain/scope/RumActionScope.kt 97.77% <ø> (+0.56%) ⬆️
...g/android/rum/internal/domain/scope/RumRawEvent.kt 100.00% <100.00%> (ø)
...roid/rum/internal/domain/scope/RumResourceScope.kt 94.58% <100.00%> (-1.08%) ⬇️
.../android/rum/internal/domain/scope/RumViewScope.kt 95.00% <100.00%> (+0.57%) ⬆️
...lin/com/datadog/android/rum/resource/ResourceId.kt 100.00% <100.00%> (ø)
...com/datadog/android/okhttp/DatadogEventListener.kt 97.44% <100.00%> (ø)
.../android/rum/internal/monitor/DatadogRumMonitor.kt 86.99% <96.67%> (+0.56%) ⬆️
.../datadog/android/okhttp/internal/rum/RequestExt.kt 66.67% <66.67%> (ø)
...n/com/datadog/android/okhttp/DatadogInterceptor.kt 72.11% <66.67%> (-1.36%) ⬇️
... and 1 more

... and 35 files with indirect coverage changes

@xgouchet xgouchet merged commit 2d1fb6c into develop Jul 19, 2024
@xgouchet xgouchet deleted the xgouchet/RUM-648/okhttp_request_id branch July 19, 2024 10:07
@xgouchet xgouchet added this to the 2.12.x milestone Jul 31, 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