Skip to content

feat: add Hints API for beforeSend callbacks - #8942

Open
itaybre wants to merge 6 commits into
mainfrom
feat/hints-api
Open

feat: add Hints API for beforeSend callbacks#8942
itaybre wants to merge 6 commits into
mainfrom
feat/hints-api

Conversation

@itaybre

@itaybre itaybre commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Add a Hints API that gives beforeSend and beforeBreadcrumb callbacks access to the raw source material of an event: the original NSError or NSException that triggered the capture, the attachments that will be sent with the event, and generic key-value storage. The new Hint class (SentryHint in ObjC) is threaded through the entire capture pipeline in SentryClient and SentryHub, and is exposed through the new beforeSendWithHint and beforeBreadcrumbWithHint callbacks, which take precedence over beforeSend/beforeBreadcrumb when both are set. The ObjC wrapper surface gets a matching SentryObjCHint type and callback properties.

Attachments can be added and removed

Before beforeSendWithHint runs, the SDK pre-populates hint.attachments with the attachments that will be sent with the event (the scope's attachments, filtered for fatal events). The list left in the hint when the callback returns is what the SDK sends, so the callback can add and remove attachments, as proposed in #1460.

The WithHint callbacks ship deprecated

They are transitional API: in v10 the hint parameter will be added to beforeSend/beforeBreadcrumb directly and the WithHint variants will be removed. The deprecation is on the setters only (via @available and DEPRECATED_MSG_ATTRIBUTE), so adopters get the warning while the SDK's internal reads stay clean.

Hint guards its state with SentryMutex, so it is safe to read and write from any queue.

Refs #1460

@github-actions

github-actions Bot commented Sep 3, 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 6a2b13b

@itaybre itaybre added the run-full-ci Allows gated GitHub Action workflows to run for a labelled pull request label Sep 3, 2026
@sentry

sentry Bot commented Sep 3, 2026

Copy link
Copy Markdown

📲 Install Builds

iOS

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

⚙️ sentry-cocoa Build Distribution Settings

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1226.20 ms 1256.87 ms 30.67 ms
Size 24.14 KiB 1.32 MiB 1.30 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
6844d69 1228.25 ms 1265.20 ms 36.95 ms
d929b8b 1227.85 ms 1265.15 ms 37.30 ms
89c6f79 1215.43 ms 1256.32 ms 40.89 ms
fc4e913 1221.61 ms 1253.82 ms 32.21 ms
487d993 1223.12 ms 1261.37 ms 38.25 ms
50fe369 1226.48 ms 1268.96 ms 42.48 ms
0f52723 1239.90 ms 1271.96 ms 32.06 ms
bf10fe6 1226.00 ms 1260.76 ms 34.76 ms
445b440 1226.80 ms 1257.72 ms 30.93 ms
c955ea9 1210.87 ms 1245.78 ms 34.91 ms

App size

Revision Plain With Sentry Diff
6844d69 24.14 KiB 1.20 MiB 1.17 MiB
d929b8b 24.14 KiB 1.18 MiB 1.16 MiB
89c6f79 24.14 KiB 1.29 MiB 1.27 MiB
fc4e913 24.14 KiB 1.17 MiB 1.15 MiB
487d993 24.14 KiB 1.24 MiB 1.21 MiB
50fe369 24.14 KiB 1.24 MiB 1.22 MiB
0f52723 24.14 KiB 1.24 MiB 1.21 MiB
bf10fe6 24.14 KiB 1.17 MiB 1.15 MiB
445b440 24.14 KiB 1.17 MiB 1.14 MiB
c955ea9 24.14 KiB 1.25 MiB 1.23 MiB

Previous results on branch: feat/hints-api

Startup times

Revision Plain With Sentry Diff
d23eee9 1221.69 ms 1261.77 ms 40.08 ms

App size

Revision Plain With Sentry Diff
d23eee9 24.14 KiB 1.32 MiB 1.30 MiB

Add a Hint class that provides metadata about the origin of
an event (original error/exception, attachments, key-value
data) flowing alongside events through the capture pipeline.

New beforeSendWithHint and beforeBreadcrumbWithHint callbacks
take precedence over their existing counterparts. The WithHint
variants are deprecated and will be removed in v10 when the
hint parameter is added to beforeSend/beforeBreadcrumb directly.

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

Left some early review comments to consider

}
}

@objc public var beforeSendWithHint: ((SentryObjCEvent, SentryObjCHint) -> SentryObjCEvent?)? {

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.

m: we should consider marking this as deprecated already and mention that this will be the default in v10 as proposed by @NinjaLikesCheez

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.

Adding it to the public var brought a lot of issues but TIL I can add the deprecated only to the setter.
Updated now

Comment thread Sources/SentryObjCCompat/SentryObjCOptions.swift
Comment thread Sources/Swift/Protocol/SentryHint.swift Outdated
Comment thread Sources/Swift/Options.swift Outdated
Comment thread Sources/Swift/Options.swift Outdated

class SentryHintTests: XCTestCase {

func testInit_shouldHaveNilProperties() {

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.

m: Should add some concurrency tests here to verify the properties are behind locks/mutex

Comment thread Tests/SentryTests/SentryClientTests.swift
Guard Hint state with SentryMutex instead of NSLock, and deprecate
the WithHint callback setters via @available and
DEPRECATED_MSG_ATTRIBUTE, since the hint parameter moves into
beforeSend/beforeBreadcrumb in the next major version.

Pre-populate hint.attachments with the scope attachments before
beforeSendWithHint runs and treat the hint list as authoritative
afterwards, so the callback can remove attachments as well as add
them. Add concurrency tests for Hint and attachment add/remove
coverage for the client.
@itaybre
itaybre marked this pull request as ready for review September 5, 2026 01:04

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

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.

Reviewed by Cursor Bugbot for commit 6a2b13b. Configure here.

alwaysAttachStacktrace:alwaysAttachStacktrace
isFatalEvent:isFatalEvent
hint:hint];
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty hints skip attachment population

Medium Severity

The no-hint prepareEvent overloads allocate a fresh empty Hint and invoke beforeSendWithHint without calling populateHintAttachments. Callers such as captureReplayEvent and saveCrashTransaction therefore present an empty attachment list, and any add or remove the callback performs is discarded because those paths never read that hint afterward.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6a2b13b. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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