Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segment context not propagated when asyncio.run_in_executor is used #446

Open
fangyi-zhou opened this issue Nov 1, 2024 · 1 comment
Open

Comments

@fangyi-zhou
Copy link

(Minimised) Example code:

import asyncio

from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all
from aws_xray_sdk.core.async_context import AsyncContext

import boto3

xray_recorder.configure(service="Test app", sampling=False, context=AsyncContext())
patch_all()


def run_task():
    s3_client = boto3.client("s3")
    s3_client.list_buckets()


async def main():
    loop = asyncio.get_running_loop()
    xray_recorder.begin_segment("test")
    await loop.run_in_executor(None, run_task)
    xray_recorder.end_segment()


asyncio.run(main())

Output:

cannot find the current segment/subsegment, please make sure you have a segment open
No segment found, cannot begin subsegment s3.
cannot find the current segment/subsegment, please make sure you have a segment open
cannot find the current segment/subsegment, please make sure you have a segment open
No segment to end
cannot find the current segment/subsegment, please make sure you have a segment open

I understand from the README that when using a thread pool (which is the default executor), the trace entity needs to be manually propagated. Could it be propagated automatically?

I'm asking because in the use case I have, a 3rd party library I'm using is making the call so I couldn't patch the call sites easily.

@avr2002
Copy link

avr2002 commented Nov 13, 2024

Hi,
Today, while working with xray, I stumbled upon this library; haven't tried it; I'm not sure, but it looks like it might solve your problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants