Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#446 2 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
aws, python

调研方向

从 README 中关于线程池 trace 传播的指导以及与 loop.run_in_executor 一起使用的 AsyncContext 入口点开始。复现最小化示例,然后跟踪 run_task 如何获取当前 segment,并验证在传播为自动进行时,示例能够完成且不会出现 segment 缺失或 subsegment 缺失的消息。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
Python
星标
340
派生
148
平均合并
7 天 8 小时
30 天内合并 PR
2

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

aws/aws-xray-sdk-python 的其他 Issue

查看 aws/aws-xray-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。