sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

`beforeSend` skipped if breadcrumbs > 100

Open lhunath opened this issue 1 year ago • 5 comments

Platform

iOS

Environment

Develop

Installed

Swift Package Manager

Version

8.25.0

Did it work on previous versions?

No response

Steps to Reproduce

  1. set SentryOptions.maxBreadcrumbs = 500
  2. add SentryOptions.beforeSend = cb
  3. add many breadcrumbs, eg. for i in 1 ... 150 { SentrySDK.addBreadcrumb(Breadcrumb(level: .debug, category: "test")) }
  4. send a message eg. SentrySDK.capture(message: "testing")
  5. 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

lhunath avatar Apr 30 '24 20:04 lhunath

Note:

  • discovered here: https://github.com/getsentry/sentry/issues/70342
  • restoring the maxBreadcrumbs cap to the default 100 allows 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 beforeSend call-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.maxBreadcrumbs set to 500, and still I am seeing this odd behaviour.

That clearly suggests a bug to me, my beforeSend should not be skipped, it does important things.

_Originally posted by @lhunath in https://github.com/getsentry/sentry/issues/70342

lhunath avatar Apr 30 '24 21:04 lhunath

Thanks for opening this issue and the additional notes, we'll investigate and fix this 🙏

kahest avatar May 02 '24 12:05 kahest

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.

brustolin avatar May 02 '24 15:05 brustolin

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 avatar May 02 '24 15:05 lhunath

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

kahest avatar May 06 '24 13:05 kahest

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 🥀

getsantry[bot] avatar May 28 '24 07:05 getsantry[bot]