feat(pymongo): add PyMongo integration
Adds breadcrumbs and performance traces for PyMongo queries using an
official monitoring API. Integration is similar to the one available in
OpenTelemetry, tags set to values recommended for attributes by OT as
specified in Span Operations guidelines.
PyMongo version selection explanation:
- 3.1 - introduction of monitoring API. Only Python 2.7 and 3.6 supported.
- 3.12 - latest 3.x release, support for 2.7, 3.6-3.9 (3.7-3.9 added in various minor releases between 3.1 and 3.12).
- 4.0 - no support for 2.7, added support for 3.10.
- 4.1 - no support for 3.6.0-3.6.1.
- 4.2 - no support for any 3.6.
Uses MockupDB for tests (Python implementation of MongoDB protocol server). mongomock is a reimplementation of the MongoClient and doesn't support tracing. This way we get real world like results. Note that pymongo has changed queries sent for some requests between 3.1 and 3.12 (probably 3.7 or 3.11) so additional responder is necessary to handle tests with 3.1.
There is no support for GridFS nor server connect/disconnect events. Those can be added in the future although I don't think there is an API similar to pymongo.monitoring for GridFS (so monkeypatching would be necessary in this one).
closes #1585
BTW I really hope spans like db.find are visible in DB spans panel and similar places, didn't have time to dive into implementation details of span retrieval endpoints.
Docs PR: https://github.com/getsentry/sentry-docs/pull/5469
Hey @Agalin and @polina-popova ! Sorry for the delay! And thank you soo much for the great work! I will have a look at this today, and I will also be the person to help bring this into a release sooner than later :-)
Could you maybe rebase your branch again on the newest master, so everything is up to date? Thanks!
Awesome. Rebased to master (clean rebase as the only existing file is tox.ini)
Oh, and please fix also the linting errors. Thanks!
I have now added a new function for nicer PII stripping, could you review my PR @Agalin : https://github.com/operasoftware/sentry-python/pull/1 Thank you very much!
I have to stay home to take care of my daughter today (some childrens sickness) Could you fix the tests please @Agalin ? I think when the tests are green we are ready to merge.
@antonpirker tests now pass in tox on my machine (tested 2.7 with pymongo 3.1 and 3.8 with 4.2).
Amazing @Agalin ! Thank you so much again for your great work!
Hey @Agalin if you now rebase on the new master again, it will be merged automatically (after running the tests once again)
Ah. My rebase stopped automerge. 😓 @antonpirker can you reapprove?
Done! (now for the documentation)
Hey everyone!
This will be released today!
Again: thank you so much for your contribution, it is really great work! @Agalin If you send me your shipping address to [email protected] I can send you a little "thank you" gift.
Yay, it's happening! Should I add an entry in the main Sentry codebase that adds integration recommendation? It couldn't be done earlier as version number is required.