sentry-javascript: TypeError: Converting circular structure to JSON

Package + Version

  • @sentry/browser 5.19.1

Version:

5.19.1

Description

Error:

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'b'
    |     property 'collections' -> object with constructor 'Object'
    |     property '149e8f85-8be3-4957-b38b-981c51e38da7' -> object with constructor 'Object'
 ...
  at JSON.stringify(<anonymous>)
  at eventToSentryRequest(../node_modules/@sentry/core/esm/request.js:6:20)
  at sendEvent(../node_modules/@sentry/browser/esm/transports/fetch.js:28:25)
  at sendEvent(../node_modules/@sentry/core/esm/basebackend.js:38:25)
  at call(../node_modules/@sentry/core/esm/baseclient.js:318:28)
  at _sendEvent(../node_modules/@sentry/browser/esm/client.js:45:37)
  at onfulfilled(../node_modules/@sentry/core/esm/baseclient.js:377:27)
  at onfulfilled(../node_modules/@sentry/utils/esm/syncpromise.js:136:33)
  at ? (../node_modules/@sentry/utils/esm/syncpromise.js:61:33)
  at Array.forEach(<anonymous>)
  at _executeHandlers(../node_modules/@sentry/utils/esm/syncpromise.js:55:28)
  at _attachHandler(../node_modules/@sentry/utils/esm/syncpromise.js:46:19)
  at executor(../node_modules/@sentry/utils/esm/syncpromise.js:126:19)
  at new e(../node_modules/@sentry/utils/esm/syncpromise.js:73:13)
  at then(../node_modules/@sentry/utils/esm/syncpromise.js:125:16)
  at executor(../node_modules/@sentry/core/esm/baseclient.js:348:18)
  at new e(../node_modules/@sentry/utils/esm/syncpromise.js:73:13)
  at _processEvent(../node_modules/@sentry/core/esm/baseclient.js:346:16)
  at apply(../node_modules/@sentry/core/esm/baseclient.js:91:14)
  at _invokeClient(../node_modules/@sentry/hub/esm/hub.js:58:39)
  at captureEvent(../node_modules/@sentry/hub/esm/hub.js:184:14)
  at handler(../node_modules/@sentry/browser/esm/integrations/globalhandlers.js:61:28)
  at triggerHandlers(../node_modules/@sentry/utils/esm/instrument.js:77:17)
  at Q.onerror(../node_modules/@sentry/utils/esm/instrument.js:434:9)

This is how we’re reporting exceptions:

    // error: Error, severityLevel: Severity, extras: { [key: string]: any } 
    withScope(scope => {
      scope.setExtras(extras)
      scope.setLevel(severityLevel)
      captureException(error)
    })

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 8
  • Comments: 90 (35 by maintainers)

Commits related to this issue

Most upvoted comments

We have thousand of errors like this with sentry/5.26.0/bundle.min.js (and previous versions) :

Converting circular structure to JSON
    --> starting at object with constructor 'HTMLDivElement'
    |     property 'jQuery3410215558066319917922' -> object with constructor 'Object'
    |     property 'datetimepicker' -> object with constructor 'k...

and

JSON.stringify cannot serialize cyclic structures.

and

cyclic object value

Why not stringify in a try catch block?

Hi all, I ran into the same issue, _experiments.ensureNoCircularStructures also didn’t help. Are there any updates on this?

Ok small update here: I just merged https://github.com/getsentry/sentry-javascript/pull/5851 which is supposed to get rid of the circular reference error in case a circular reference error would occur. It’s probably not bulletproof yet and also has a slight performance penalty - which is why this hopefully won’t be a permanent solution.

We still hope this will fix the issue. It will be included in the next release of the SDK. I’ll respond to this issue again once it’s released to let everybody know.

What I did to debug https://github.com/getsentry/sentry-javascript/pull/3727 is:

  1. Get reproducible error scenario
  2. Add Sentry.addGlobalEventProcessor(event => { debugger; })
  3. Trigger error
  4. Call JSON.stringify(error) and trace the source of circular reference

Once we have the source, we’ll be able to reproduce and patch it easily. The biggest problem now is actually knowing the source of that reference.

Unfortunately our codebase is closed-source. I can’t send a public link.

I understand. If you send the link to the actual Sentry event (the link underneath the event id indicated in the first screenshot below) rather than a share link, it will only be accessible to Sentry staff (it will be hidden behind your org’s sign-in). And if it would make you feel more comfortable, in that link, feel free to redact everything before events - all I really need is the last bit, shown in the second screenshot (event id and project id).

image

image

If that still feels like too much, we can either move this part of the conversation to a support ticket (just tell them I sent you) or start with the first things I’d look at:

  1. does the event have the skippedNormalization tag?
  2. are you using straight up @sentry/node, or a wrapper SDK?
  3. in your JSON, there should be somewhere where it says [Circular ~] - presumably somewhere under request, given your fix. Assuming that’s where it is, it’d be helpful to know the full path to the value (and anything else within the vicinity which might give some clue as to its origin).
  4. Do you have any of our integrations (besides the Express one) turned on?

Thanks for helping me debug this!

This fix has been released with https://github.com/getsentry/sentry-javascript/releases/tag/7.14.1, please let us know if there are any issues!

The thing I’m most concerned about is if this is an actual error that Sentry is attempting to log or if it’s just a random Sentry error we can ignore. Hopefully not the former, which means we’re missing potentially important issues.

https://sentry.io/share/issue/2e7b97a984c14c3496eada587f42efc2/

@lforst @kamilogorek @lobsterkatie Any insight into this?

This is still an issue for us, and we’re using @sentry/browser 7.5.0.

Converting circular structure to JSON
    --> starting at object with constructor 'constructor'
    |     property 'response' -> object with constructor 'constructor'
    --- property 'request' closes the circle

Hi, all. This should be fixed in 7.1.0. If it ever crops up again, though, please let us know!

Thanks, @ffxsam. It turns out there was a bug in my debugging code (ironic, right?), which was fixed in 6.19.3. I’ll be curious to see if any events come through using that version of the SDK or later.

My guess is this will go out in 6.17.1.

UPDATE: Released. Looking forward to hearing what data you get back!

Okay, I’d like to get this finally figured out, so in the above PR I threw everything I could think of at the metaphorical wall, and we’ll see what sticks.

There’s much more detail in the PR description, but TL;DR, the ensureNoCircularStructures flag is no longer needed (because now renormalization only happens when there’s a problem) and various logs/tags have been added to try to help us differentiate between different possible unhappy paths.

Once it’s released, @ffxsam and anyone else still having the problem, can you please try it out and report back? Even if this “fixes” the problem, it’s really just a bandaid, and I’d still like to discover the reason it’s happening in the first place and fix it for real.

(Given that (hopefully) the JSON.stringify errors will no longer show up directly, you might consider adding an alert rule so that you know when events with the new tags come in.)

Thanks!

@kamilogorek That setting didn’t help, and this is becoming a major issue for us. We can’t get visibility into some errors because Sentry failed to log them properly.

We really need a solution or workaround for this. If there’s anything we can do on our end to help pinpoint this, please let me know.

CleanShot 2021-11-14 at 12 17 08

I’ll try that out next time I get some free time, unless someone beats me to it!