Repository navigation
Conversation
Add SentryWebViewTracing.addTracePropagation(to:options:), which injects the current trace as sentry-trace and baggage meta tags into pages on allowed hosts before page scripts run, so @sentry/browser continues the trace on pageload. It accepts a WKUserContentController, WKWebViewConfiguration, WKWebView, or SwiftUI WebPage.Configuration (iOS 26+). SentryObjC exposes it as SentryObjCWebViewTracing. The injected script and host normalization match sentry-react-native and sentry-java. Using the API records the WebViewTracePropagation integration for adoption. Extract the outgoing trace lookup from the network tracker into SentryOutgoingTrace so both paths share it.
|
Size Analysis1 component analyzed iOS Builds
|
📲 Install BuildsiOS
|
Run @sentry/browser in the iOS-Swift WebView screen so its pageload continues the app's trace, and add a SwiftUI WebPage screen on iOS 26. UI tests check that both pages see the injected trace before their own scripts run. Add a test that loads a page in a real WebPage created from a configuration with Sentry's script.
🚨 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:
|
Move SentryObjCWebViewTracing, its tests, and the SentryObjC API snapshots to a separate pull request stacked on this one, to keep this one focused on the Swift API.
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 973db93. Configure here.
itaybre
left a comment
There was a problem hiding this comment.
Almost LGTM, one small question
|
|
||
| /// For testing purposes, we want to be able to change the DSN and store it to disk. In a real app, you shouldn't need this behavior. | ||
| var dsn: String? { | ||
| public var dsn: String? { |
There was a problem hiding this comment.
m: any reason to make this public?
| SentryWebViewTracePropagation.recordUsage(in: SentrySDK.isEnabled ? SentrySDKInternal.currentHub() : nil) | ||
| return SentryWebViewTracePropagation.install( | ||
| allowedHosts: options.allowedHosts, | ||
| on: userContentController, | ||
| hub: SentryWebViewTracePropagation.currentHub |
There was a problem hiding this comment.
m: Both SentrySDKInternal.currentHub() and SentryWebViewTracePropagation.currentHub should be the same Hub, right?
Would it be possible for the hub be passed as an argument?
📜 Description
Adds
SentryWebViewTracing.addTracePropagation(to:options:), which connects the app's trace with web content in aWKWebView.Before any page script runs, the current trace is written into pages from the allowed hosts as
sentry-traceandbaggagemeta tags, using aWKUserScriptat document start. A@sentry/browserrunning in the page then continues the trace on pageload.WKWebView,WKWebViewConfiguration,WKUserContentController, or SwiftUIWebPage.Configuration(iOS 26+). The SentryObjC API follows in feat: Add SentryObjC WebView trace propagation #9488.allowedHostsis a trust boundary, separate fromtracePropagationTargets. A page matches an entry's host or its subdomains.sentry-transactionis removed frombaggage.WebViewTracePropagationintegration for feature adoption.capacitor://localhost) work; App Transport Security already blocks plain http by default.💡 Motivation and Context
💚 How did you test it?
WKWebViewand SwiftUIWebPage@sentry/browseron the iOS 26.5 simulatorWKWebView:WebView:📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps