You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e1f91da
Browse filesBrowse the repository at this point in the historyBrowse files
description: "Learn about importing the aiomysql integration and how it captures queries from aiomysql as spans."
4
+
---
5
+
6
+
The aiomysql integration captures queries from [aiomysql](https://github.com/aio-libs/aiomysql/) as spans.
7
+
8
+
## Install
9
+
10
+
Install `sentry-sdk` from PyPI:
11
+
12
+
```bash {tabTitle:pip}
13
+
pip install sentry-sdk
14
+
```
15
+
```bash {tabTitle:uv}
16
+
uv add sentry-sdk
17
+
```
18
+
19
+
## Configure
20
+
21
+
Add `AioMySQLIntegration()` to your `integrations` list:
22
+
23
+
```python
24
+
import sentry_sdk
25
+
from sentry_sdk.integrations.aiomysql import AioMySQLIntegration
26
+
27
+
sentry_sdk.init(
28
+
dsn="___PUBLIC_DSN___",
29
+
# Set traces_sample_rate to 1.0 to capture 100%
30
+
# of transactions for tracing.
31
+
traces_sample_rate=1.0,
32
+
# Add data like inputs and responses;
33
+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
34
+
send_default_pii=True,
35
+
integrations=[
36
+
AioMySQLIntegration(),
37
+
],
38
+
)
39
+
```
40
+
41
+
## Verify
42
+
43
+
```python
44
+
import sentry_sdk
45
+
from sentry_sdk.integrations.aiomysql import AioMySQLIntegration
46
+
import aiomysql
47
+
import asyncio
48
+
49
+
sentry_sdk.init(
50
+
dsn="___PUBLIC_DSN___",
51
+
traces_sample_rate=1.0,
52
+
send_default_pii=True,
53
+
integrations=[
54
+
AioMySQLIntegration(),
55
+
],
56
+
)
57
+
58
+
asyncdefmain():
59
+
conn =await aiomysql.connect(
60
+
host="localhost",
61
+
port=3306,
62
+
user="root",
63
+
password="root",
64
+
db="test",
65
+
)
66
+
try:
67
+
with sentry_sdk.start_transaction(name="testing_sentry"):
68
+
asyncwith conn.cursor() as cur:
69
+
await cur.execute("SELECT 'Hello World'")
70
+
result =await cur.fetchone()
71
+
finally:
72
+
conn.close()
73
+
74
+
asyncio.run(main())
75
+
```
76
+
77
+
This will create a transaction called `testing_sentry` in the Performance section of [sentry.io](https://sentry.io) and will create a span for the `SELECT` statement.
78
+
79
+
It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io).
0 commit comments