sentry-javascript: TypeError: Converting circular structure to JSON
- Review the documentation: https://docs.sentry.io/
- Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- Use the latest release: https://github.com/getsentry/sentry-javascript/releases
- Provide a link to the affected event from your Sentry account -> https://sentry.io/organizations/deepnote/issues/1781748535/events/7e842347bdf44a49a68f1648d581de36
Package + Version
-
@sentry/browser5.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
- ref(core): Renormalize event only after stringification errors (#4425) Since at least 5.19.1, we've had a bug[1] which causes events not to be able to be serialized for transmission, because they con... — committed to getsentry/sentry-javascript by lobsterkatie 2 years ago
- ref(core): Log `normalizeDepth` when normalization is skipped (#4574) Continuing debugging of https://github.com/getsentry/sentry-javascript/issues/2809. In the most recent example event there[1], it... — committed to getsentry/sentry-javascript by lobsterkatie 2 years ago
- fix(core): Use correct version of event when tagging normalization (#4780) In https://github.com/getsentry/sentry-javascript/pull/4425, various hacks were added to the SDK to try to diagnose the root... — committed to getsentry/sentry-javascript by lobsterkatie 2 years ago
- ref(core): Log `normalizeDepth` type when normalization is skipped (#4870) This is a follow up to https://github.com/getsentry/sentry-javascript/pull/4425 and https://github.com/getsentry/sentry-java... — committed to getsentry/sentry-javascript by lobsterkatie 2 years ago
- chore(core): Remove circular JSON debugging hacks (#5267) In https://github.com/getsentry/sentry-javascript/pull/4425 and https://github.com/getsentry/sentry-javascript/pull/4574, various hacks were ... — committed to getsentry/sentry-javascript by lobsterkatie 2 years ago
We have thousand of errors like this with
sentry/5.26.0/bundle.min.js(and previous versions) :and
JSON.stringify cannot serialize cyclic structures.and
cyclic object valueWhy not stringify in a try catch block?
Hi all, I ran into the same issue,
_experiments.ensureNoCircularStructuresalso 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:
Sentry.addGlobalEventProcessor(event => { debugger; })JSON.stringify(error)and trace the source of circular referenceOnce 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.
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).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:
skippedNormalizationtag?@sentry/node, or a wrapper SDK?[Circular ~]- presumably somewhere underrequest, 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).Expressone) 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/browser7.5.0.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
ensureNoCircularStructuresflag 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.stringifyerrors 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.
I’ll try that out next time I get some free time, unless someone beats me to it!