Duplicate HTTP breadrumbs
Platform
iOS
Installed
Swift Package Manager
Version
8.3.2
Steps to Reproduce
- enable network breadcrumbs
- make fatal error
Similar events were caught on iOS 14.8/14.8.1 only with crashes
Expected Result
Similar HTTP Requests breadcrumbs appear once
Actual Result
Similar HTTP Requests breadcrumbs appear twice
Are you willing to submit a PR?
No response
I just tried this with our sample app and couldn't reproduce the issue. Are you sure that you don't have two similar web requests? Can you provide us with more details so we can reproduce the issue, please?
Hello, I have checked with Proxyman that we make only one request, so It could not be duplicated by requests. I could not reproduce this issue too, but on prod env we are getting such problems. It looks similar with this issue
this issue does not have a 100% chance of reproducing
@looneytsci, thanks for the update. Does it only happen for HTTP requests or also other breadcrumb types?
@philipphofmann Yes, it happens only for requests. Every request in breadcrumbs duplicates
Again @looneytsci, I'm unable to reproduce your problem; I'm sorry. Thanks for pointing out https://github.com/getsentry/sentry-react-native/issues/1409, but the problem there was that all breadcrumbs were duplicated. I doubt we have a similar problem in how we attach the breadcrumbs, as this problem only happens for network breadcrumbs. Can you maybe check timestamps of the breadcrumbs of the event JSON? You can do this by clicking on the JSON button of an event

The JSON looks something like this:
"breadcrumbs": {
"values": [
{
"timestamp": 1683029337.71,
"type": "debug",
"category": "started",
"level": "info",
"message": "Breadcrumb Tracking"
},
{
"timestamp": 1683029337.737,
"type": "navigation",
"category": "device.orientation",
"level": "info",
"data": {
"position": "portrait"
}
}
]
}
If the timestamps are the same, we know they are duplicate breadcrumbs. If they are different, we know that the SDK created two.
Furthermore, if you could somehow reproduce this, it would be great if you could attach your debugger in SentryNetworkTracker, as it adds network breadcrumbs here:
https://github.com/getsentry/sentry-cocoa/blob/14a11017fca0d2f366ade2bd13bb35be7fcecdc8/Sources/Sentry/SentryNetworkTracker.m#L415-L444
@philipphofmann same one

timestamps are the same
Thanks, @looneytsci and @alex93133, for the update. @alex93133, do you only experience this for HTTP breadcrumbs and only fatal errors / crashes?
I found a possible cause for this problem. We swizzle the setState of NSURLSessionTask here https://github.com/getsentry/sentry-cocoa/blob/fd6a31ce3940224432d2ece19de8c052bec3c3d2/Sources/Sentry/SentryNetworkTrackingIntegration.m#L72-L78
If the NSURLSessionTask sets the state twice in a row to NSURLSessionTaskStateRunning, we could end up creating two breadcrumbs and also possibly capture two failed requests.
https://github.com/getsentry/sentry-cocoa/blob/fd6a31ce3940224432d2ece19de8c052bec3c3d2/Sources/Sentry/SentryNetworkTracker.m#L275-L278
@brustolin, as you wrote most of the network tracking logic, does this sound plausible to you? If yes, debounce mechanism or something similar could help us to solve this problem.
@philipphofmann It does make sense, theoretically its possible. I never saw NSURLSession doing this, but our code it is open to this possibility.
Then let's fix this edge case and see if it solves the problem.