Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeSend skipped if breadcrumbs > 100 #3928

Open
lhunath opened this issue Apr 30, 2024 · 5 comments
Open

beforeSend skipped if breadcrumbs > 100 #3928

lhunath opened this issue Apr 30, 2024 · 5 comments

Comments

@lhunath
Copy link
Contributor

lhunath commented Apr 30, 2024

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
Copy link
Contributor Author

lhunath commented Apr 30, 2024

Note:

  • discovered here: Large events strategy sentry#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 getsentry/sentry#70342

@kahest
Copy link
Member

kahest commented May 2, 2024

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

@brustolin
Copy link
Contributor

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.

@lhunath
Copy link
Contributor Author

lhunath commented May 2, 2024

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
}

@kahest
Copy link
Member

kahest commented May 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for: Product Owner
Status: Waiting for: Community
Status: Needs More Information
Development

No branches or pull requests

3 participants