Skip to content

Commit 00fe1e7

Browse files
Agalinimatwawanaantonpirker
authored
Docs for PyMongo integration (#5469)
* Docs for PyMongo integration * Added guide for PyMongo * Added wizard for PyMongo Co-authored-by: Agalin <[email protected]> Co-authored-by: Szymon Soloch <[email protected]> Co-authored-by: Isabel <[email protected]> Co-authored-by: Anton Pirker <[email protected]>
1 parent 17a4449 commit 00fe1e7

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: PyMongo
3+
description: "Learn about using Sentry with PyMongo."
4+
---
5+
6+
The PyMongo integration adds support for [PyMongo](https://www.mongodb.com/docs/drivers/pymongo/), the official MongoDB driver.
7+
8+
9+
## Install
10+
11+
Install `sentry-sdk` from PyPI with the `pymongo` extra:
12+
13+
```bash
14+
pip install --upgrade 'sentry-sdk[pymongo]'
15+
```
16+
17+
## Configure
18+
19+
To configure the SDK, initialize it before creating any of PyMongo's MongoClient instances:
20+
21+
```python
22+
import sentry_sdk
23+
from sentry_sdk.integrations.pymongo import PyMongoIntegration
24+
25+
26+
sentry_sdk.init(
27+
dsn="___PUBLIC_DSN___",
28+
integrations=[
29+
PyMongoIntegration(),
30+
],
31+
32+
# Set traces_sample_rate to 1.0 to capture 100%
33+
# of transactions for performance monitoring.
34+
# We recommend adjusting this value in production,
35+
traces_sample_rate=1.0,
36+
)
37+
```
38+
39+
<Note>
40+
41+
In the future, we will make this auto-enabling, so you won't need to add the `PyMongoIntegration` to your
42+
`sentry_sdk.init()` call. Instead, the Sentry SDK will detect the presence of PyMongo and will set up the integration
43+
automatically.
44+
45+
</Note>
46+
47+
48+
## Behavior
49+
50+
The following information about your MonogDB queries will be available to you on Sentry.io:
51+
52+
- Performance traces for all MongoDB queries
53+
- Breadcrumbs for all MongoDB queries
54+
- Personal identifiable information (PII) will be stripped from all MongoDB queries if `send_default_pii` is disabled in the SDK. (This was tested for PyMongo 4.2 and below, but "should" also be future proof)
55+
56+
![MongoDB query details are shown as a waterfall diagram](mongodb-query-performance-details.png)
57+
58+
### Other MongoDB libraries
59+
60+
PyMongo is an official synchronous driver for MongoDB. It means that many other Python libraries interacting with
61+
MongoDB use it under the hood, like, for example `mongoengine` (always) or `umongo` (if selected from multiple available
62+
drivers). Official async MongoDB driver called `Motor` uses PyMongo under the hood as well.
63+
Queries generated by those libraries will also be monitored.
64+
65+
If you use a different driver (for example, `TxMongo`), this integration won't work.
66+
67+
### Mongomock
68+
69+
While `mongomock` can be used to replace `PyMongo` in tests, it doesn't implement all features available in the official
70+
driver. This integration will not generate any breadcrumbs or spans from `mongomock`'s clients.
Loading

src/wizard/python/pymongo.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: PyMongo
3+
doc_link: https://docs.sentry.io/platforms/python/guides/pymongo/
4+
support_level: production
5+
type: library
6+
---
7+
8+
The PyMongo integration adds support for [PyMongo](https://www.mongodb.com/docs/drivers/pymongo/), the official MongoDB
9+
driver. It adds breadcrumbs and performace traces for all queries.
10+
11+
1. Install `sentry-sdk` from PyPI with the `pymongo` extra:
12+
13+
```bash
14+
pip install --upgrade 'sentry-sdk[pymongo]'
15+
```
16+
17+
2. To configure the SDK, initialize it before creating any of PyMongo's MongoClient instances:
18+
19+
```python
20+
import sentry_sdk
21+
from sentry_sdk.integrations.pymongo import PyMongoIntegration
22+
23+
24+
sentry_sdk.init(
25+
dsn="___PUBLIC_DSN___",
26+
integrations=[
27+
PyMongoIntegration(),
28+
],
29+
30+
# Set traces_sample_rate to 1.0 to capture 100%
31+
# of transactions for performance monitoring.
32+
# We recommend adjusting this value in production,
33+
traces_sample_rate=1.0,
34+
)
35+
```
36+
37+
The above configuration captures both breadcrumbs and performance data. To reduce the volume of performance data
38+
captured, change `traces_sample_rate` to a value between 0 and 1.

0 commit comments

Comments
 (0)