Skip to content

Commit e1f91da

Browse files
feat: Add aiomysql integration page (#18298)
1 parent af2963d commit e1f91da

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: aiomysql
3+
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+
async def main():
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+
async with 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).
80+
81+
## Supported Versions
82+
83+
- aiomysql: 0.3+
84+
85+
<Include name="python-use-older-sdk-for-legacy-support.mdx" />

‎docs/platforms/python/integrations/index.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
3131

3232
| | **Auto-enabled** |
3333
| -------------------------------------------------------------------------------------------------------------------------------------- | :--------------: |
34+
| <LinkWithPlatformIcon platform="python.aiomysql" label="aiomysql" url="/platforms/python/integrations/aiomysql" /> | |
3435
| <LinkWithPlatformIcon platform="python.asyncpg" label="asyncpg" url="/platforms/python/integrations/asyncpg" /> | ✓ |
3536
| <LinkWithPlatformIcon platform="python.clickhouse-driver" label="ClickHouse" url="/platforms/python/integrations/clickhouse-driver" /> | ✓ |
3637
| <LinkWithPlatformIcon platform="python.pymongo" label="MongoDB" url="/platforms/python/integrations/pymongo" /> | ✓ |

0 commit comments

Comments
 (0)