`beforeSend` skipped if breadcrumbs > 100
Platform
iOS
Environment
Develop
Installed
Swift Package Manager
Version
8.25.0
Did it work on previous versions?
No response
Steps to Reproduce
- set
SentryOptions.maxBreadcrumbs = 500 - add
SentryOptions.beforeSend = cb - add many breadcrumbs, eg.
for i in 1 ... 150 { SentrySDK.addBreadcrumb(Breadcrumb(level: .debug, category: "test")) } - send a message eg.
SentrySDK.capture(message: "testing") - put a breakpoint in the beforeSend callback
Expected Result
breakpoint is triggered when the event needs to get sent.
Actual Result
no breakpoint is triggered and the event is sent as-is, without any beforeSend processing.
Are you willing to submit a PR?
No response
Note:
- discovered here: https://github.com/getsentry/sentry/issues/70342
- restoring the
maxBreadcrumbscap to the default100allows the break-point to get fired again, we see only the last 100 breadcrumbs present in the event.
What's curious to note is that when I add > 100 breadcrumbs to the scope, Sentry stops invoking
beforeSend:[Sentry] [debug] [SentryCrashStackCursor_SelfThread:61] Retrieving backtrace with async swift stitching... [Sentry] [debug] [SentryCrashStackCursor_SelfThread:78] Finished retrieving backtrace.At this point, adding < 100 breadcrumbs halts the code in the
beforeSendcall-back. Adding > 100 breadcrumbs skips the callback and proceeds directly to sending the event off:[Sentry] [debug] [SentryFileManager:321] Writing envelope to path: /Users/hubstaff/Library/Developer/CoreSimulator/Devices/🆔/data/Containers/Data/Application/🆔/Library/Caches/io.sentry/a999994c4ff1a25927f709eb50500057d6cdae95/envelopes/1714509134.833000-00000-🆔.json [...]I should note that I have
SentryOptions.maxBreadcrumbsset to500, and still I am seeing this odd behaviour.That clearly suggests a bug to me, my
beforeSendshould not be skipped, it does important things.
_Originally posted by @lhunath in https://github.com/getsentry/sentry/issues/70342
Thanks for opening this issue and the additional notes, we'll investigate and fix this 🙏
Hello @lhunath. Do you have any other settings on your SentryOptions. I tried to follow your steps to reproduce and the app do stop in the breakpoint.
open func startCrashLogger() {
SentrySDK.start(configureOptions: self.sentry(options:))
}
open func sentry(options: Sentry.Options) {
// TODO: https://github.com/getsentry/team-mobile/issues/24
// options.enabled = false
options.sendDefaultPii = true
options.environment = AppInfo.shared.configuration.lowercased()
options.enablePreWarmedAppStartTracing = true
options.enableMetricKit = true
options.swiftAsyncStacktraces = true
options.initialScope = self.sentry(scope:)
options.beforeSend = self.sentry(event:)
options.attachScreenshot = true
options.attachViewHierarchy = true
switch AppInfo.shared.bundleIdentifier {
case "com.netsoft.Hubstaff":
options.dsn = <>
options.tracesSampleRate = 0.01
options.profilesSampleRate = 0.01
default:
options.dsn = <>
options.tracesSampleRate = 0.1
options.profilesSampleRate = 0.1
}
}
open func sentry(scope: Sentry.Scope) -> Sentry.Scope {
scope.setTag(value: AppInfo.shared.build, key: "app.build")
scope.setTag(value: AppInfo.shared.version, key: "app.version")
scope.setTag(value: AppInfo.shared.configuration, key: "app.configuration")
scope.setTag(value: AppInfo.shared.reference, key: "app.reference")
scope.setTag(value: AppInfo.shared.revision, key: "app.revision")
return scope
}
open func sentry(event: Sentry.Event) -> Sentry.Event? {
event
}
@lhunath I tried to repro the described behavior with the above settings, but didn't manage to. beforeSend is called as expected and the number of breadcrumbs capped at 500. Where do you invoke startCrashLogger from?
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀