Skip to content

Commit 5ddd942

Browse files
committed
Docs for PyMongo integration
* Added guide for PyMongo * Added wizard for PyMongo
1 parent 3fad325 commit 5ddd942

File tree

2 files changed

+99
-0
lines changed

2 files changed

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

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 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)