How do you use Sentry?
Sentry Saas (sentry.io)
Version
2.30.0
Steps to Reproduce
- Init Sentry with AsyncioIntegration.
- Create ThreadPoolExecutor
- Create async task using asyncio.create_task
- Inside the task call loop.run_in_executor
Code to reproduce the issue:
import asyncio
import threading
from concurrent.futures import ThreadPoolExecutor
from time import sleep
import sentry_sdk
from sentry_sdk.integrations.asyncio import AsyncioIntegration
def init_sentry():
sentry_sdk.init(
dsn="",
traces_sample_rate=1.0,
integrations=[
AsyncioIntegration(),
],
)
@sentry_sdk.trace
def task_1():
print(f"Task 1 thread ID: {threading.get_ident()}")
sleep(0.5)
async def main():
init_sentry()
print(f"Main thread ID: {threading.get_ident()}")
executor = ThreadPoolExecutor()
for i in range(3):
task = asyncio.create_task(worker_task(executor, i))
await task
async def worker_task(executor: ThreadPoolExecutor, i: int):
with sentry_sdk.start_transaction(
op="function", name="main_thread"
):
print(f"\nWorker task {i} thread ID: {threading.get_ident()}")
loop = asyncio.get_event_loop()
await loop.run_in_executor(executor, task_1)
if __name__ == "__main__":
asyncio.run(main())
Expected Result
Spans created in tasks that run in a ThreadPoolExecutor should be included in the transactions sent to Sentry when AsyncioIntegration is enabled.
Actual Result
Spans created in tasks that run in a ThreadPoolExecutor are missing from the transactions sent to Sentry.
Only the first execution contains all the spans:

Subsequent executions are missing spans created inside executor:

Removing AsyncioIntegration integration solves the issue but then many automatic async related spans are missing. Our application uses asyncio but executes many CPU intensive blocking tasks inside executor.
I also tried Sentry 3.0.0a2 and it has the same issue.
How do you use Sentry?
Sentry Saas (sentry.io)
Version
2.30.0
Steps to Reproduce
Code to reproduce the issue:
Expected Result
Spans created in tasks that run in a ThreadPoolExecutor should be included in the transactions sent to Sentry when
AsyncioIntegrationis enabled.Actual Result
Spans created in tasks that run in a ThreadPoolExecutor are missing from the transactions sent to Sentry.
Only the first execution contains all the spans:

Subsequent executions are missing spans created inside executor:

Removing
AsyncioIntegrationintegration solves the issue but then many automatic async related spans are missing. Our application uses asyncio but executes many CPU intensive blocking tasks inside executor.I also tried Sentry 3.0.0a2 and it has the same issue.