Skip to content

feat: Add SentryObjC WebView trace propagation - #9488

Merged
antonis merged 17 commits into
mainfrom
feat/webview-trace-propagation-objc
Nov 4, 2026
Merged

antonis merged 17 commits into
mainfrom
feat/webview-trace-propagation-objc

Conversation

@antonis

@antonis antonis commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

📜 Description

Stacked on #9474, which adds SentryWebViewTracing.

Exposes WebView trace propagation through the SentryObjC SDK.

SentryObjCWebViewTracingOptions *options =
    [[SentryObjCWebViewTracingOptions alloc] initWithAllowedHosts:@[ @"app.example.com" ]];
[SentryObjCWebViewTracing addTracePropagationToWebView:webView options:options];
  • SentryObjCWebViewTracing has overloads for WKUserContentController, WKWebViewConfiguration, and WKWebView, and forwards to SentryWebViewTracing. The SwiftUI WebPage overload is Swift-only.
  • Returns YES if the script was added. Called off the main thread, it returns NO instead of trapping.
  • Available on iOS, macOS (including Mac Catalyst) and visionOS.

💡 Motivation and Context

Split out of #9474 to keep it focused on the Swift API. Public APIs need to be exposed through SentryObjC before release.

💚 How did you test it?

  • Added SentryObjCWebViewTracingTests for each overload, repeated calls, a closed SDK, and calls off the main thread
  • Built SentryObjC for iOS and ran the tests on macOS

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

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.
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.
Move the lookup of the trace propagated to outgoing requests from
SentryNetworkTracker into SentryOutgoingTrace: the span bound to the
scope if it belongs to a tracer, otherwise the scope's propagation
context. Behavior is unchanged.

This lets WebView trace propagation reuse the same lookup.
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.
Expose SentryWebViewTracing through the SentryObjC SDK as
SentryObjCWebViewTracing and SentryObjCWebViewTracingOptions, with
overloads for WKUserContentController, WKWebViewConfiguration, and
WKWebView. Calls off the main thread return NO.
@github-actions

github-actions Bot commented Oct 29, 2026 •

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

Generated by 🚫 dangerJS against 2651418

@antonis antonis added the run-full-ci Allows gated GitHub Action workflows to run for a labelled pull request label Oct 29, 2026
@sentry

sentry Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

📲 Install Builds

iOS

🔗 App Name App ID Version Configuration
SDK-Size io.sentry.sample.SDK-Size 9.32.0 (1) Release

⚙️ sentry-cocoa Build Distribution Settings

@sentry

sentry Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Size Analysis

1 component analyzed

iOS Builds

Name Configuration Version Download Size Install Size
SDK-Size (iOS)
io.sentry.sample.SDK-Size
Release 9.32.0 (1) 1.2 MB (-19 B) 3.2 MB (0 B)

Configure sentry-cocoa status check rules

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

✅ 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 7d10643. Configure here.

@antonis
antonis marked this pull request as ready for review October 29, 2026 13:01
@antonis
antonis requested review from a team and noahsmartin as code owners October 29, 2026 13:01
@antonis
antonis requested review from 0xadam-brown, alwx, itaybre, philprime and runningcode and removed request for a team October 29, 2026 13:01
@antonis
antonis requested a review from buenaflor October 29, 2026 13:02

@itaybre itaybre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Resolve the current hub once in addTracePropagation and pass it to
both the adoption marker and the script install, and replace the test
Hub double with real hubs.

Keep SentrySDKWrapper.dsn internal: the sample pages read the DSN from
SentrySDK.startOption instead. Merge the changelog entry into the
existing Features section of Unreleased.
The SwiftPM package tests run on the iOS Simulator without a host app.
There, WebKit's web content process intermittently becomes
unresponsive, so the two WebView page-load tests time out. The Xcode
unit test plans and the iOS-Swift UI tests keep covering real page
loads.
Base automatically changed from feat/webview-trace-propagation to main November 4, 2026 09:00
@antonis
antonis merged commit e530f31 into main Nov 4, 2026
328 of 332 checks passed
@antonis
antonis deleted the feat/webview-trace-propagation-objc branch November 4, 2026 10:58
antonis added a commit to getsentry/sentry-docs that referenced this pull request Nov 5, 2026
<!-- Keep the urgency section so automation can prioritize this PR. You
may delete other sections you don't need. -->

## DESCRIBE YOUR PR

Updates the Apple WebView page for the new trace connection in the Cocoa
SDK. It replaces the statement that the SDK doesn't interact with web
views with setup for `SentryWebViewTracing.addTracePropagation`, which
writes the app's trace into `WKWebView` pages as `sentry-trace` and
`baggage` meta tags before page scripts run, so `@sentry/browser`
continues it on pageload.

- Swift and SentryObjC examples, plus a SwiftUI `WebPage` section (iOS,
macOS, visionOS 26+)
- `allowedHosts` matching and the trust warning, aligned with the [React
Native WebView
page](https://docs.sentry.io/platforms/react-native/configuration/webview/)
- The snapshot behavior, supported platforms, and limitations

Resolves getsentry/sentry-cocoa#9136

> ⚠️ SDK changes: getsentry/sentry-cocoa#9474 (Swift API) and
getsentry/sentry-cocoa#9488 (SentryObjC API). The version alert says
`9.33.0`; it will be updated if the release differs. Keep this as a
draft until those PRs ship.

## IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
Select exactly one option. For deadlines, replace `YYYY-MM-DD` with the
due date. You can update this information later by editing the PR
description.

- [ ] Urgent deadline (GA date, etc.): YYYY-MM-DD
- [ ] Other deadline: YYYY-MM-DD
- [x] No deadline: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
supplied a deadline.

Thanks in advance for your help!

## PRE-MERGE CHECKLIST

_Make sure you've checked the following before merging your changes:_

- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)

## EXTRA RESOURCES

- [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved run-full-ci Allows gated GitHub Action workflows to run for a labelled pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants