-
-
Notifications
You must be signed in to change notification settings - Fork 461
[android] Capture network request/response details when using SentryOkHttpListener #4919
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
base: main
Are you sure you want to change the base?
Conversation
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- [android] Capture network request/response details when using SentryOkHttpListener ([#4919](https://github.com/getsentry/sentry-java/pull/4919))If none of the above apply, you can opt out of this check by adding |
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| ee747ae | 357.79 ms | 421.84 ms | 64.05 ms |
| ae7fed0 | 293.84 ms | 380.22 ms | 86.38 ms |
| 9fbb112 | 404.51 ms | 475.65 ms | 71.14 ms |
| 27d7cf8 | 397.90 ms | 498.65 ms | 100.75 ms |
| a416a65 | 333.78 ms | 410.37 ms | 76.59 ms |
| d217708 | 411.22 ms | 430.86 ms | 19.63 ms |
| 539ca63 | 313.51 ms | 355.43 ms | 41.92 ms |
| 23d6b12 | 354.10 ms | 408.38 ms | 54.28 ms |
| 14ff5ee | 419.75 ms | 495.73 ms | 75.98 ms |
| ce0a49e | 532.00 ms | 609.96 ms | 77.96 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| ee747ae | 1.58 MiB | 2.10 MiB | 530.95 KiB |
| ae7fed0 | 1.58 MiB | 2.12 MiB | 551.77 KiB |
| 9fbb112 | 1.58 MiB | 2.11 MiB | 539.18 KiB |
| 27d7cf8 | 1.58 MiB | 2.12 MiB | 549.42 KiB |
| a416a65 | 1.58 MiB | 2.12 MiB | 555.26 KiB |
| d217708 | 1.58 MiB | 2.10 MiB | 532.97 KiB |
| 539ca63 | 1.58 MiB | 2.12 MiB | 551.41 KiB |
| 23d6b12 | 1.58 MiB | 2.10 MiB | 532.31 KiB |
| 14ff5ee | 1.58 MiB | 2.10 MiB | 535.08 KiB |
| ce0a49e | 1.58 MiB | 2.10 MiB | 532.94 KiB |
Previous results on branch: 43jay/MOBILE-935
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 6687052 | 321.98 ms | 383.35 ms | 61.38 ms |
| 1c4ba0c | 302.22 ms | 367.21 ms | 64.98 ms |
| fedc731 | 325.81 ms | 383.02 ms | 57.21 ms |
| da92356 | 319.12 ms | 388.73 ms | 69.61 ms |
| 154fb27 | 336.98 ms | 387.10 ms | 50.12 ms |
| 1a07f53 | 341.15 ms | 378.86 ms | 37.71 ms |
| 790a163 | 339.64 ms | 436.57 ms | 96.94 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 6687052 | 1.58 MiB | 2.13 MiB | 556.25 KiB |
| 1c4ba0c | 1.58 MiB | 2.13 MiB | 556.34 KiB |
| fedc731 | 1.58 MiB | 2.13 MiB | 557.33 KiB |
| da92356 | 1.58 MiB | 2.13 MiB | 556.24 KiB |
| 154fb27 | 1.58 MiB | 2.13 MiB | 557.32 KiB |
| 1a07f53 | 1.58 MiB | 2.12 MiB | 553.02 KiB |
| 790a163 | 1.58 MiB | 2.12 MiB | 553.01 KiB |
Run tests ./gradlew :sentry:test --tests="*NetworkDetailCaptureUtilsTest*"
Reuse existing logic that retrieves optional SentryOkHttpEvent for the okhttp3.Call, and optionally provide NetworkRequestData for adding to Breadcrumb Hint in SentryOkHttpEvent#finish
cf95f21 to
2e9b796
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.
Bug: Duplicate HTTP headers lost in conversion
The toMap() function loses duplicate HTTP headers with the same name. When iterating through OkHttp headers and inserting into a Map<String, String>, duplicate header names get overwritten, keeping only the last value. This causes data loss for headers like Set-Cookie, Accept, or Vary that commonly appear multiple times in HTTP messages. The captured network details will be incomplete when responses or requests contain duplicate headers.
sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpInterceptor.kt#L265-L272
sentry-java/sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpInterceptor.kt
Lines 265 to 272 in 22bb832
| /** Extracts headers from OkHttp Headers object into a map */ | |
| private fun okhttp3.Headers.toMap(): Map<String, String> { | |
| val headers = linkedMapOf<String, String>() | |
| for (i in 0 until size) { | |
| headers[name(i)] = value(i) | |
| } | |
| return headers | |
| } |
📜 Description
Widely enable network details capture (request/response bodies and headers - docs) by adding support to
SentryOkHttpEventListener.Updates CHANGELOG.
💡 Motivation and Context
Part of [Mobile Replay] Capture Network request/response bodies.
Network Details extraction depends on okhttp3.Interceptor (
SentryOkHttpInterceptor) to intercept http requests and extract the relevant data to the Breadcrumb Hint.However,
SentryOkHttpInterceptoris only responsible for sending Breadcrumb data when the okhttp client doesn't use Sentry'sSentryOkHttpEventListener(see #4796).Given registering
SentryOkHttpEventListeneris the default gradle plugin behavior, this implementation has limited value. So this PR modifiesSentryOkHttpInterceptorto pass network details data to the correspondingSentryOkHttpEventto be captured when sending the Breadcrumb from that path.💚 How did you test it?
Manual testing.
📝 Checklist
I added GH Issue ID & Linear ID
No new PII added or SDK only sends newly added PII if
sendDefaultPIIis enabled. N/ANo breaking change or entry added to the changelog. see CHANGELOG.md in this PR
No breaking change for hybrid SDKs or communicated to hybrid SDKs. No sentry.api changes here
Review from the native team if needed. No native changes
I added tests to verify the changes.
Confirm that the gradle plugin always registers SentryOkHttpInterceptor
🔮 Next steps