Inconsistent event schemas between SDKs (JS / Python) #1537
Replies: 3 comments 3 replies
-
hey @alexmojaki this is a really unconventional use case, but bonus points for creativity! I'm surprised the rest of the SDK works at all since we never tested in webassembly before. ^^
Yes, there might be some inconsistencies between SDKs in this regard, because our event schema allows both a direct list of objects or nested under
Unfortunately, this really counts as an unsupported use case so you'll just have to deal with the inconsistencies on your end, sorry! If you need me to confirm something about the schema, you can ask me here again, but I'll close this issue and move it to a discussion. |
Beta Was this translation helpful? Give feedback.
-
Pyodide is great, you can expect any pure Python code that works in CPython to work perfectly in Pyodide, even if it relies heavily on CPython implementation details, until of course it has to interact with the outside world like send a network request.
Thanks for the explanation. It seems then that there a few issues that are reasonably worth fixing:
The use case doesn't seem to be the most relevant thing here. It's clear just from the existence of pages like https://develop.sentry.dev/sdk/event-payloads/types/ that Sentry cares about types and schemas, and I think getting this stuff right is worth it. The use case is an example of why these schemas are worth it, because the two SDKs have fit together for some time and still very nearly do, producing benefits that you didn't even anticipate. I think this is a thing of beauty worth being proud of and preserving: I also think it's a use case worth supporting at least a little. It's becoming increasingly common for languages like Python to be used in the browser, it's still just as useful as always to use Sentry to monitor errors in those cases, and it doesn't require unusual effort from either users or Sentry. It would be unreasonable to ask you to start adding code and tests specifically for webassembly, but this isn't close to that, it's just a matter of the JS SDK correctly following the official schema. The use case is also much more general than 'Python in the browser'. For example, I've considered reusing this exact technique at my work to start monitoring our Python code with Sentry. The Python code runs in a server, but in a secure sandbox that has no network access, so it would send the event to the parent process running NodeJS. I expect this would work exactly as well as the browser case, i.e. fully apart from the breadcrumbs issue. I also imagine the result would be similar with other languages instead of Python, as long as that SDK also produces an object with I don't personally need this fix, since the workaround is simple and I've verified that it works: alexmojaki/futurecoder@4b6a75d But I think that this tiny inconsistency in what seems to be otherwise perfect compatibility is tragic. It seems likely that other people will try to do similar things, run into the same error, and conclude that it's impossible, without having any way of knowing how close they were. |
Beta Was this translation helpful? Give feedback.
-
The Python SDK could just change the breadcrumbs after |
Beta Was this translation helpful? Give feedback.
-
How do you use Sentry?
Sentry Saas (sentry.io)
Version
1.9.0
Steps to Reproduce
Background: I use
sentry_sdk
in Python running in the browser with Pyodide to collect a serialised Sentry event about a Python exception without actually sending it, because Python code for sending network requests doesn't work in the browser. The code for that is here: https://github.com/alexmojaki/futurecoder/blob/e09f016bd69f893d3eb81e1a4bfa804953aedb4e/core/utils.py#L205-L225 . The event is returned to JS which sends it to the server usingSentry.captureEvent
. I'm@sentry/react
, and it and all its dependencies like@sentry/browser
are on version 7.8.1.In summary:
sentry_sdk.init()
to set a custom transport to intercept events.sentry_sdk.capture_exception()
to collect an event, but don't send it.Sentry.captureEvent()
in JS.Expected Result
The event is captured successfully and can be viewed on sentry.io. This has in fact been working great for a while, and the UI shows me info from both the JS and Python SDKs in one event.
Actual Result
Sentry.captureEvent()
in JS runs into aTypeError: (e.breadcrumbs || []) is not iterable
, which itself actually gets captured by Sentry and sent instead:The problem is that in the Python event,
breadcrumbs
is adict
with a keyvalues
mapping to a list. But JS expectsbreadcrumbs
to just be the list (array) rather than a dict (object). If I setevent.breadcrumbs = event.breadcrumbs.values
in JS, then everything goes back to working perfectly. However this doesn't mean much since in this caseevent.breadcrumbs
is just{values: []}
. I don't know if there are sometimes keys other thanvalues
, or if the lists themselves are also sometimes incompatible between the SDKs.I don't know to what extent the different SDKs are meant to have compatible schema, but it seems like it's been working well so far and it'd be a pity to lose that. Also, I don't know if this issue belongs here or in a JS repo.
Beta Was this translation helpful? Give feedback.
All reactions