Skip to content

feat: add Hints API for beforeSend callbacks - #8942

Merged
itaybre merged 7 commits into
mainfrom
feat/hints-api
Sep 7, 2026
Merged

itaybre merged 7 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 822cb83

@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 1229.96 ms 1270.81 ms 40.85 ms
Size 24.14 KiB 1.32 MiB 1.30 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
fc4e913 1231.79 ms 1267.89 ms 36.11 ms
6f28fd8 1229.98 ms 1271.73 ms 41.75 ms
a7c42d9 1217.25 ms 1253.98 ms 36.73 ms
230cc86 1225.33 ms 1258.67 ms 33.34 ms
5556249 1208.87 ms 1246.60 ms 37.72 ms
8ed81c1 1227.47 ms 1249.24 ms 21.77 ms
92fada5 1217.60 ms 1252.89 ms 35.30 ms
6d9f89d 1226.37 ms 1260.94 ms 34.57 ms
318f8af 1213.09 ms 1246.21 ms 33.13 ms
01ffe09 1208.52 ms 1240.94 ms 32.42 ms

App size

Revision Plain With Sentry Diff
fc4e913 24.14 KiB 1.17 MiB 1.15 MiB
6f28fd8 24.14 KiB 1.30 MiB 1.28 MiB
a7c42d9 24.14 KiB 1.15 MiB 1.13 MiB
230cc86 24.14 KiB 1.25 MiB 1.23 MiB
5556249 24.14 KiB 1.29 MiB 1.27 MiB
8ed81c1 24.14 KiB 1.23 MiB 1.21 MiB
92fada5 24.14 KiB 1.17 MiB 1.15 MiB
6d9f89d 24.14 KiB 1.26 MiB 1.23 MiB
318f8af 24.14 KiB 1.30 MiB 1.28 MiB
01ffe09 24.14 KiB 1.29 MiB 1.27 MiB

Previous results on branch: feat/hints-api

Startup times

Revision Plain With Sentry Diff
9790269 1226.20 ms 1256.87 ms 30.67 ms
d23eee9 1221.69 ms 1261.77 ms 40.08 ms

App size

Revision Plain With Sentry Diff
9790269 24.14 KiB 1.32 MiB 1.30 MiB
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

Comment thread Sources/SentryObjCCompat/SentryObjCOptions.swift
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
Comment thread Tests/SentryTests/Protocol/SentryHintTests.swift
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.

Comment thread Sources/Sentry/SentryClient.m

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

LGTM without superseding Phil's comment :)

Comment thread Sources/Sentry/SentryClient.m Outdated
Comment thread Sources/Sentry/SentryClient.m Outdated

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

LGTM

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

The API changes LGTM

Remove misplaced comment and fix nil-check style for
consistency with the rest of the file.
@itaybre
itaybre enabled auto-merge (squash) September 7, 2026 19:35
@itaybre
itaybre merged commit 567b0b3 into main Sep 7, 2026
284 of 288 checks passed
@itaybre
itaybre deleted the feat/hints-api branch September 7, 2026 20:18
@linear-code

linear-code Bot commented Sep 8, 2026

Copy link
Copy Markdown

COCOA-1891

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.

4 participants