Skip to content

feat(network-details): Extract network details data to Session Replay#7590

Open
43jay wants to merge 5 commits intomobile-935/hook-up-sentry-network-trackerfrom
mobile-935/breadcrumb-to-rrweb
Open

feat(network-details): Extract network details data to Session Replay#7590
43jay wants to merge 5 commits intomobile-935/hook-up-sentry-network-trackerfrom
mobile-935/breadcrumb-to-rrweb

Conversation

@43jay
Copy link
Copy Markdown
Collaborator

@43jay 43jay commented Mar 4, 2026

📜 Description

Upload network details data (SentryNetworkRequestData) extracted by SentryNetworkTracker to the session replay backend.

SentryNetworkRequestData
Stored on the NSURLSessionTask while waiting for data (see previous prs)

SentryNetworkRequestData *networkRequestData
        = objc_setAssociatedObject(sessionTask, &SentryNetworkRequestDataKey);

Stored in the Breadcrumb data after task has completed (addBreadcrumbForSessionTask) (THIS PR)

breadcrumbData[SentryReplayNetworkDetailsKey]

Extracted from Breadcrumb into RRWebEvent (SentrySRDefaultBreadcrumbConverter) (THIS PR)

 SentryNetworkRequestData.serialize

💡 Motivation and Context

Last leg of data upload; now data is visible in replay dash.

💚 How did you test it?

Manual Testing with iOS-Swift test app

  1. Build and install
xcodebuild -workspace Sentry.xcworkspace -scheme iOS-Swift -sdk iphonesimulator -destination  'platform=iOS Simulator,name=iPhone 16 Pro' clean build

xcrun simctl install "iPhone 16 Pro"  ~/Library/Developer/Xcode/DerivedData/Sentry-*/Build/Products/Debug-iphonesimulator/iOS-Swift.app
  1. Navigate to Extras > Network Details

  2. Initiate different types of request

  3. Navigate to sentry.io test project and confirm session replay 'Network' tab shows requests with correct body and headers.

https://sentry-sdks.sentry.io/explore/replays/f5cff413ffd94561819...

  • Request + Response Headers correctly extracted
options.sessionReplay.networkRequestHeaders = [
                "User-Agent",
                "X-Custom-Header",
                "X-Request-ID"
            ]
            options.sessionReplay.networkResponseHeaders = [
                "Server",
                "Access-Control-Allow-Origin",
                "access-control-allow-credentials"
            ]
image
  • Formurlencoded request/response bodies correctly extracted as structured data
  • Binary content correct not extracted / extracted as placeholder
  • JSON Body over 150KB limit correctly truncated and 'fixed up' (server-side) with expected warning in UI

Unit tests

Summary:

Test Suite Tests Failures Status
SentryNSURLSessionTaskSearchTests 3 0
SentryReplayNetworkDetailsIntegrationTests 4 0
SentryReplayOptionsNetworkTests 11 0
SentryReplayOptionsObjcTests 2 0
SentryReplayOptionsTests 77 0
Total 97 0

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled. gated by SentryReplayOptions#networkDetailAllowUrls
  • I updated the docs if needed.
  • I updated the wizard if needed. n/a
  • Review from the native team if needed. n/a
  • No breaking change or entry added to the changelog. future PR #skip-changelog
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

Closes #7591

@linear
Copy link
Copy Markdown

linear bot commented Mar 4, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against dd6c72f

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 23.72881% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.895%. Comparing base (44d3c4a) to head (dd6c72f).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ionReplay/SentrySRDefaultBreadcrumbConverter.swift 9.090% 30 Missing ⚠️
.../SessionReplay/RRWeb/SentryRRWebOptionsEvent.swift 13.333% 13 Missing ⚠️
Sources/Sentry/SentryNetworkTracker.m 80.000% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                               Coverage Diff                               @@
##           mobile-935/hook-up-sentry-network-tracker     #7590       +/-   ##
===============================================================================
+ Coverage                                     84.881%   84.895%   +0.014%     
===============================================================================
  Files                                            486       486               
  Lines                                          29116     29170       +54     
  Branches                                       12639     12673       +34     
===============================================================================
+ Hits                                           24714     24764       +50     
- Misses                                          4354      4357        +3     
- Partials                                          48        49        +1     
Files with missing lines Coverage Δ
...ons/SessionReplay/SentryReplayNetworkDetails.swift 96.644% <100.000%> (ø)
Sources/Sentry/SentryNetworkTracker.m 97.746% <80.000%> (+12.646%) ⬆️
.../SessionReplay/RRWeb/SentryRRWebOptionsEvent.swift 59.375% <13.333%> (-40.625%) ⬇️
...ionReplay/SentrySRDefaultBreadcrumbConverter.swift 63.953% <9.090%> (-34.160%) ⬇️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44d3c4a...dd6c72f. Read the comment docs.

@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from 5f57b05 to a4f221a Compare March 4, 2026 21:03
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from 7cda42c to c8da718 Compare March 4, 2026 21:03
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from a4f221a to fde4a5e Compare March 4, 2026 22:00
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from c8da718 to e9fcc6c Compare March 4, 2026 22:00
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from fde4a5e to 8b6853c Compare March 6, 2026 16:33
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from e9fcc6c to 46f7481 Compare March 6, 2026 16:33
@43jay 43jay marked this pull request as draft March 6, 2026 18:44
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from 46f7481 to f35da26 Compare March 6, 2026 19:25
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from 8b6853c to 624e1f5 Compare March 6, 2026 19:25
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from f35da26 to f4312a8 Compare March 9, 2026 18:09
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch 2 times, most recently from d80d538 to d08a33e Compare March 9, 2026 19:02
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from f4312a8 to af0159e Compare March 9, 2026 19:02
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from d08a33e to d5a8320 Compare March 9, 2026 19:48
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from af0159e to 3852520 Compare March 9, 2026 19:48
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from d5a8320 to 80df62b Compare March 9, 2026 20:51
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from 3852520 to 58aafe3 Compare March 9, 2026 20:51
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from 3d0176a to 99f38e3 Compare March 10, 2026 21:06
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from fea8910 to 05a57ee Compare March 17, 2026 16:37
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from 99f38e3 to bdadd3e Compare March 17, 2026 16:50
@43jay 43jay marked this pull request as ready for review March 17, 2026 16:50
})

// Add Network Details data when available
if let networkRequestData = breadcrumb.data?["_networkDetails"] as? [String: 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.

h: Please add unit tests for this serialization

Copy link
Copy Markdown
Collaborator Author

@43jay 43jay Mar 19, 2026

Choose a reason for hiding this comment

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

I have SentryNetworkDetailsData:serialize tests here
Tests/SentryTests/Networking/SentryReplayNetworkDetailsIntegrationTests.swift

introduced on #7585

// Add network details if available for session replay
SentryReplayNetworkDetails *networkDetails
= objc_getAssociatedObject(sessionTask, &SentryNetworkDetailsKey);
if (networkDetails) {
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.

h: Please add unit test for this case

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

can you elaborate on what needs testing here?

Copy link
Copy Markdown
Collaborator Author

@43jay 43jay Mar 19, 2026

Choose a reason for hiding this comment

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

@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from 05a57ee to e15e24c Compare March 18, 2026 19:25
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch 2 times, most recently from 030d2e4 to f986bfa Compare March 18, 2026 19:34
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from e15e24c to c84ff73 Compare March 18, 2026 19:34
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from f986bfa to 1fc4171 Compare March 19, 2026 18:31
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from d43fd3c to efa243d Compare March 19, 2026 19:28
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from c84ff73 to 5ea8b46 Compare March 19, 2026 19:28
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from efa243d to 8079837 Compare March 19, 2026 19:46
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch 2 times, most recently from a741581 to a925d4a Compare March 19, 2026 20:00
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch 2 times, most recently from 22fcb76 to bb3966d Compare March 23, 2026 19:04
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from a925d4a to 44d3c4a Compare March 23, 2026 19:04
43jay added 5 commits March 24, 2026 16:12
…Event

Add populated NetworkRequestData to breadcrumb data
 SentryNetworkTracker#addBreadcrumbForSessionTask

Read NetworkRequestData from breadcrumb when converting for session replay
 SentrySRDefaultBreadcrumbConverter
… breadcrumb

#7588 (comment)

in testing, the completionHandler is invoked after setState(.completed)
returns. However based on research this is not guaranteed so lock so ensure
no concurrent access to obj_get|setAssociatedState
RRWebOptionsEvent payload shows up in the `tags` panel on a
session replay.
networkDetailHasUrls is required to light-up the UI.
@43jay 43jay force-pushed the mobile-935/breadcrumb-to-rrweb branch from bb3966d to dd6c72f Compare March 24, 2026 20:29
@github-actions
Copy link
Copy Markdown
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentryNetworkTracker.m


private func addNetworkDetails(from networkData: [String: Any], to data: inout [String: Any]) {
// Add top-level network metadata
if let method = networkData["method"] as? 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.

h: Are network details without a method even accepted? Are all envelopes valid if just a statusCode or just a responseBodySize etc. is set? If yes, please add test cases where only individual values are available, so we can make sure that this behaviour is locked down

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.

2 participants