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

Duplicate HTTP breadrumbs

Open looneytsci opened this issue 3 years ago • 12 comments

Platform

iOS

Installed

Swift Package Manager

Version

8.3.2

Steps to Reproduce

  1. enable network breadcrumbs
  2. make fatal error

Similar events were caught on iOS 14.8/14.8.1 only with crashes

Снимок экрана 2023-04-27 в 14 42 15

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

looneytsci avatar Apr 27 '23 11:04 looneytsci

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?

philippsuess avatar Apr 27 '23 14:04 philippsuess

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

looneytsci avatar Apr 27 '23 15:04 looneytsci

this issue does not have a 100% chance of reproducing

looneytsci avatar Apr 27 '23 15:04 looneytsci

@looneytsci, thanks for the update. Does it only happen for HTTP requests or also other breadcrumb types?

philippsuess avatar Apr 28 '23 04:04 philippsuess

@philipphofmann Yes, it happens only for requests. Every request in breadcrumbs duplicates

looneytsci avatar Apr 28 '23 08:04 looneytsci

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 Screenshot 2023-05-02 at 14 17 38

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

philippsuess avatar May 02 '23 12:05 philippsuess

@philipphofmann same one 1

alex93133 avatar May 03 '23 09:05 alex93133

timestamps are the same

looneytsci avatar May 03 '23 12:05 looneytsci

Thanks, @looneytsci and @alex93133, for the update. @alex93133, do you only experience this for HTTP breadcrumbs and only fatal errors / crashes?

philippsuess avatar May 03 '23 13:05 philippsuess

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.

philippsuess avatar May 03 '23 13:05 philippsuess

@philipphofmann It does make sense, theoretically its possible. I never saw NSURLSession doing this, but our code it is open to this possibility.

brustolin avatar May 03 '23 14:05 brustolin

Then let's fix this edge case and see if it solves the problem.

philippsuess avatar May 04 '23 11:05 philippsuess