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

feat(pymongo): add PyMongo integration

Open Agalin opened this issue 3 years ago • 2 comments

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

Agalin avatar Aug 31 '22 12:08 Agalin

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.

Agalin avatar Aug 31 '22 12:08 Agalin

Docs PR: https://github.com/getsentry/sentry-docs/pull/5469

Agalin avatar Aug 31 '22 13:08 Agalin

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!

antonpirker avatar Oct 27 '22 08:10 antonpirker

Awesome. Rebased to master (clean rebase as the only existing file is tox.ini)

Agalin avatar Oct 27 '22 09:10 Agalin

Oh, and please fix also the linting errors. Thanks!

antonpirker avatar Oct 27 '22 13:10 antonpirker

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!

antonpirker avatar Oct 28 '22 12:10 antonpirker

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 avatar Nov 03 '22 06:11 antonpirker

@antonpirker tests now pass in tox on my machine (tested 2.7 with pymongo 3.1 and 3.8 with 4.2).

Agalin avatar Nov 03 '22 13:11 Agalin

Amazing @Agalin ! Thank you so much again for your great work!

antonpirker avatar Nov 04 '22 08:11 antonpirker

Hey @Agalin if you now rebase on the new master again, it will be merged automatically (after running the tests once again)

antonpirker avatar Nov 04 '22 09:11 antonpirker

Ah. My rebase stopped automerge. 😓 @antonpirker can you reapprove?

Agalin avatar Nov 04 '22 09:11 Agalin

Done! (now for the documentation)

antonpirker avatar Nov 04 '22 10:11 antonpirker

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.

antonpirker avatar Nov 14 '22 11:11 antonpirker

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.

Agalin avatar Nov 14 '22 21:11 Agalin