Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Segment context not propagated when `asyncio.run_in_executor` is used

Open
#446 2 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
aws, python

Research direction

Start with the README's guidance on thread-pool trace propagation and the AsyncContext entry point used with loop.run_in_executor. Reproduce the minimized example, then trace how run_task obtains the current segment and verify that the example completes without missing-segment or missing-subsegment messages when propagation is automatic.

Written by the indexing model from the issue text.

Description

(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.

Dominant language
Python
Stars
339
Forks
148
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aws/aws-xray-sdk-python

All issues in aws/aws-xray-sdk-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.