title | description |
---|---|
asyncio |
Learn about the asyncio integration and how it adds support for applications the asyncio module. |
The AsyncioIntegration
integrates with applications doing concurrent code execution using Python's asyncio module.
pip install --upgrade 'sentry-sdk'
Add AsyncioIntegration()
to your list of integrations
, enable tracing and be sure to call sentry_sdk.init()
at the beginning of the first async
function you call, as shown in the example below.
If you call sentry_sdk.init()
outside of an async
function in an async application, the SDK will not behave as expected.
<OnboardingOptionButtons options={[ 'error-monitoring', 'performance', 'profiling', ]} />
import sentry_sdk
from sentry_sdk.integrations.asyncio import AsyncioIntegration
async def main():
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
# ___PRODUCT_OPTION_START___ performance
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
# ___PRODUCT_OPTION_END___ performance
# ___PRODUCT_OPTION_START___ profiling
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0,
# ___PRODUCT_OPTION_END___ profiling
integrations=[
AsyncioIntegration(),
],
)
# your code goes here.
...
asyncio.run(main())
Trigger an error in your code and see it show up in sentry.io.
import asyncio
import sentry_sdk
from sentry_sdk.integrations.asyncio import AsyncioIntegration
async def my_task():
1 / 0 # raises an error!
async def main():
sentry_sdk.init(...) # same as above
asyncio.create_task(my_task())
asyncio.run(main())
- All unhandled exceptions in tasks will be captured
- Every executed Task will be instrumented and show up in the performance waterfall on Sentry.io
- Python: 3.7+