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
I am having an issue with correctly tracking a transaction in a multithreaded context. We use a threadpool executor to execute some functions on a series of tasks. On each task, we use the executor to perform one function synchronously (wait for the result) and one function asynchronously (do not wait for the result). The asynchronous function will finish the transaction when it completes, meanwhile the main thread moves on to the next task. As a result, there will be conditions where the main thread has started a new transaction while the previous one is still completing in the previous task's async_work function.
On the sentry performance tab, I see correct traces. The child transactions are correctly rendered. My issue is for manually captured exceptions, sentry_sdk.capture_exception. These issues maintain a link to the correct trace, but for some reason are rendered with the wrong transaction name. Appreciate all insight here!
Below is a minimal example of the circumstance:
import time
from concurrent.futures import ThreadPoolExecutor
import sentry_sdk
import sentry_sdk.scope
from structlog import get_logger
from src.utils.sentry import init_sentry
logger = get_logger(__name__)
TASKS = [{"taskId": i} for i in range(5)]
def sync_work(transaction):
with transaction.start_child(op="task", name="sync"):
logger.info("Running sync work")
def async_work(transaction):
with transaction.start_child(op="task", name="async"):
logger.info("Running async work")
time.sleep(2)
logger.info("Finished async work")
sentry_sdk.capture_exception(Exception("Async work failed"))
transaction.finish()
def main():
init_sentry()
with ThreadPoolExecutor(max_workers=4) as executor:
for task in TASKS:
try:
transaction = sentry_sdk.start_transaction(name="test-task", op="task")
sync_result = executor.submit(sync_work, transaction)
sync_result.result()
executor.submit(async_work, transaction)
except Exception as err:
logger.error(err)
if __name__ == "__main__":
main()
Expected Result
The exception should show the right transaction name
Actual Result
The text was updated successfully, but these errors were encountered:
How do you use Sentry?
Sentry Python SDK
Version
2.19.0 and 1.43.0 (tried with both versions)
Steps to Reproduce
I am having an issue with correctly tracking a transaction in a multithreaded context. We use a threadpool executor to execute some functions on a series of tasks. On each task, we use the executor to perform one function synchronously (wait for the result) and one function asynchronously (do not wait for the result). The asynchronous function will finish the transaction when it completes, meanwhile the main thread moves on to the next task. As a result, there will be conditions where the main thread has started a new transaction while the previous one is still completing in the previous task's
async_work
function.On the sentry
performance
tab, I see correct traces. The child transactions are correctly rendered. My issue is for manually captured exceptions,sentry_sdk.capture_exception
. These issues maintain a link to the correct trace, but for some reason are rendered with the wrong transaction name. Appreciate all insight here!Below is a minimal example of the circumstance:
Expected Result
The exception should show the right transaction name
Actual Result
The text was updated successfully, but these errors were encountered: