Skip to content

RUM-14782: Capture OkHttp Network Headers#3204

Merged
kikoveiga merged 6 commits into
developfrom
kikoveiga/RUM-14782/capture-okhttp-network-headers
Mar 11, 2026
Merged

RUM-14782: Capture OkHttp Network Headers#3204
kikoveiga merged 6 commits into
developfrom
kikoveiga/RUM-14782/capture-okhttp-network-headers

Conversation

@kikoveiga

@kikoveiga kikoveiga commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Add new trackResourceHeaders public api in DatadogInterceptor.
  • Add new attributes for request and response headers in RumAttributes.
  • Extract the contents of these attributes in RumResourceScope and add them to the resource.
  • Business logic in ResourceHeadersExtractor.
  • Disable caches of networking libraries used in the sample app.

Motivation

Customers weren't able to easily capture network headers, having to do it manually (e.g., by creating custom attributes).

Additional notes

Here is an example taken from the sample app:

image

This is aligned with the iOS implementation:

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)

@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch from 4ed9e06 to a082ecb Compare February 27, 2026 10:37
@datadog-datadog-prod-us1

This comment has been minimized.

@kikoveiga kikoveiga changed the title [RUM-14782] Capture OkHttp Network Headers RUM-14782: Capture OkHttp Network Headers Feb 27, 2026
@codecov-commenter

codecov-commenter commented Feb 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.83193% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.38%. Comparing base (8d4c1d3) to head (ba09435).
⚠️ Report is 64 commits behind head on develop.

Files with missing lines Patch % Lines
...om/datadog/android/rum/internal/utils/StringExt.kt 39.13% 14 Missing ⚠️
...g/android/rum/resource/ResourceHeadersExtractor.kt 92.19% 4 Missing and 1 partial ⚠️
...roid/rum/internal/domain/scope/RumResourceScope.kt 72.73% 0 Missing and 3 partials ⚠️
...otlin/com/datadog/android/rum/_RumInternalProxy.kt 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3204      +/-   ##
===========================================
+ Coverage    71.29%   71.38%   +0.09%     
===========================================
  Files          938      940       +2     
  Lines        34667    34764      +97     
  Branches      5874     5893      +19     
===========================================
+ Hits         24715    24814      +99     
+ Misses        8305     8298       -7     
- Partials      1647     1652       +5     
Files with missing lines Coverage Δ
...n/com/datadog/android/okhttp/DatadogInterceptor.kt 75.36% <100.00%> (+2.16%) ⬆️
...otlin/com/datadog/android/rum/_RumInternalProxy.kt 62.50% <0.00%> (-5.68%) ⬇️
...roid/rum/internal/domain/scope/RumResourceScope.kt 93.84% <72.73%> (+2.51%) ⬆️
...g/android/rum/resource/ResourceHeadersExtractor.kt 92.19% <92.19%> (ø)
...om/datadog/android/rum/internal/utils/StringExt.kt 39.13% <39.13%> (ø)

... and 40 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch 9 times, most recently from 998a873 to 789aef2 Compare March 2, 2026 16:34
@kikoveiga kikoveiga self-assigned this Mar 2, 2026
@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch 6 times, most recently from d99452e to de59997 Compare March 2, 2026 18:37
@kikoveiga
kikoveiga marked this pull request as ready for review March 3, 2026 10:40
@kikoveiga
kikoveiga requested review from a team as code owners March 3, 2026 10:40

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de599972f2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch from de59997 to 8aed174 Compare March 3, 2026 11:04
const val GRAPHQL_ERRORS: String = "_dd.graphql.errors"

/**
* The request headers of the resource. (Map<String, String>)

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.

It is not quite clear what is expected to be key and value of this map, given that per HTTP spec headers can be repetitive, so if header name is the key, the value is List<String>. In such case how the values are joined to the single String, what is the separator?

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.

We will use comma-separated values, as also shown in the picture of the PR description.

Comment thread features/dd-sdk-android-rum/api/apiSurface Outdated
@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch 2 times, most recently from 87abd2b to 4fdeb64 Compare March 3, 2026 15:44
@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch from 4fdeb64 to a5ccb6e Compare March 3, 2026 16:34

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.

@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch from 0758bf7 to 58e640a Compare March 4, 2026 15:25
getBodyLength(response, sdkCore.internalLogger),
kind,
attributes + rumResourceAttributesProvider.onProvideAttributes(request, response, null)
attributes + headerAttributes + rumResourceAttributesProvider.onProvideAttributes(request, response, null)

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.

onProvideAttributes functions allows to return Map<String, Any?>, but in RumResourceScope you try to cast it to Map<String,String> with as?, what will happen if the client implements rumResourceAttributesProvider but returns different stuff than Map<String,String>?

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.

So does it make sense to change the order of the + here?

rumResourceAttributesProvider.onProvideAttributes(request, response, null) + attributes + headerAttributes

This is lowest to highest priority (left to right):

  1. Customer attributes — can be overridden by everything
  2. Trace/GraphQL attributes — SDK internals override customer if conflict
  3. Header attributes — always win, since the SDK controls these keys entirely

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.

yes, it's safer to put headerAttributes in the end to protect our header attributes not overwritten by user. also we need unit tests for this corner case.

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.

Moved to the end for now.

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.

As I mentioned a unit test is needed here, because this behavior can be easily broken by changing the order, so this unit test should:

  • fail - when the order is attributes + headerAttributes + rumResourceAttributesProvider.onProvideAttributes(request, response, null)
  • succeed - when the order is attributes + rumResourceAttributesProvider.onProvideAttributes(request, response, null) + headerAttributes

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.

Added a test in the end of DatadogInterceptorTest, thank you!

@kikoveiga
kikoveiga requested a review from ambushwork March 5, 2026 13:35
@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch from 453aba5 to 3806db0 Compare March 5, 2026 14:36
ambushwork
ambushwork previously approved these changes Mar 5, 2026

@ambushwork ambushwork 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.

🚀 Well done!

@satween
satween self-requested a review March 9, 2026 16:05
@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch 2 times, most recently from 094b22f to 2dbb2d2 Compare March 10, 2026 10:34
@kikoveiga
kikoveiga requested a review from satween March 10, 2026 10:34
@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch from 2dbb2d2 to cb15ea2 Compare March 10, 2026 17:19
satween
satween previously approved these changes Mar 10, 2026
Comment thread features/dd-sdk-android-rum/api/apiSurface Outdated
@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch 2 times, most recently from 67f72b4 to ca764ab Compare March 11, 2026 12:54
@kikoveiga
kikoveiga force-pushed the kikoveiga/RUM-14782/capture-okhttp-network-headers branch from ca764ab to ba09435 Compare March 11, 2026 14:56
@kikoveiga
kikoveiga requested a review from 0xnm March 11, 2026 14:58
@kikoveiga
kikoveiga merged commit 002ba9f into develop Mar 11, 2026
26 checks passed
@kikoveiga
kikoveiga deleted the kikoveiga/RUM-14782/capture-okhttp-network-headers branch March 11, 2026 16:01
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.

5 participants