aiomysql
Learn about importing the aiomysql integration and how it captures queries from aiomysql as spans.
The aiomysql integration captures queries from aiomysql as spans.
Install sentry-sdk from PyPI:
Copied
pip install sentry-sdk
pip install sentry-sdk
uv add sentry-sdk
Add AioMySQLIntegration() to your integrations list:
Copied
import sentry_sdk
from sentry_sdk.integrations.aiomysql import AioMySQLIntegration
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
# Add data like inputs and responses;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
integrations=[
AioMySQLIntegration(),
],
)
import sentry_sdk
from sentry_sdk.integrations.aiomysql import AioMySQLIntegration
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
# Add data like inputs and responses;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
integrations=[
AioMySQLIntegration(),
],
)
Copied
import sentry_sdk
from sentry_sdk.integrations.aiomysql import AioMySQLIntegration
import aiomysql
import asyncio
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
traces_sample_rate=1.0,
send_default_pii=True,
integrations=[
AioMySQLIntegration(),
],
)
async def main():
conn = await aiomysql.connect(
host="localhost",
port=3306,
user="root",
password="root",
db="test",
)
try:
with sentry_sdk.start_transaction(name="testing_sentry"):
async with conn.cursor() as cur:
await cur.execute("SELECT 'Hello World'")
result = await cur.fetchone()
finally:
conn.close()
asyncio.run(main())
import sentry_sdk
from sentry_sdk.integrations.aiomysql import AioMySQLIntegration
import aiomysql
import asyncio
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
traces_sample_rate=1.0,
send_default_pii=True,
integrations=[
AioMySQLIntegration(),
],
)
async def main():
conn = await aiomysql.connect(
host="localhost",
port=3306,
user="root",
password="root",
db="test",
)
try:
with sentry_sdk.start_transaction(name="testing_sentry"):
async with conn.cursor() as cur:
await cur.execute("SELECT 'Hello World'")
result = await cur.fetchone()
finally:
conn.close()
asyncio.run(main())
This will create a transaction called testing_sentry in the Performance section of sentry.io and will create a span for the SELECT statement.
It takes a couple of moments for the data to appear in sentry.io.
- aiomysql: 0.3+
The versions above apply for the current major version of the Python SDK. If you're looking to use Sentry with older Python or framework versions, consider using an older major version of the SDK.
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").