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

Bug: nested subsegments don't work across threads

Open
#388 4 comments 0 reactions 1 assignee View on GitHub

@srprash is already working on this.

Since Sep 28, 2023.

Assessment

This issue has not been assessed yet.

Description

pending release

We're tracking a bug where nested subsegments don't work across threads, even when using the official suggestion in the documentation.

We've managed to reproduce the issue with some minimal code:

Code snippet

from concurrent.futures import ThreadPoolExecutor

from aws_xray_sdk.core import xray_recorder

@xray_recorder.capture("## lambda handler")
def lambda_handler(event, context):
    with ThreadPoolExecutor() as pool:
        @xray_recorder.capture("## f")
        def f():
            @xray_recorder.capture("## h")
            def h():
                pass

            def g(trace_entity):
                xray_recorder.set_trace_entity(trace_entity)
                h()
                xray_recorder.clear_trace_entities()

            curr = xray_recorder.get_trace_entity()
            pool.submit(g, curr)

This produces the following XRay traces:

XRay trace

XRay Event at (2023-04-05T16:32:52.012000) with id (1-642d8694-731f0a1a6d204264677086db) and duration (0.388s)
 - 0.388s - lambda-function-url-HelloWorldFunction-sRQB00cHvXOP [HTTP: 200]
 - 0.021s - lambda-function-url-HelloWorldFunction-sRQB00cHvXOP
   - 0.223s - Initialization
   - 0.020s - Invocation
     - 0.019s - ## lambda handler
       - 0.018s - ## f
     - 0.000s - ## h
   - 0.000s - Overhead

The expected output would be for the "h" trace to be nested under "f":

Expected output

XRay Event at (2023-04-05T16:32:52.012000) with id (1-642d8694-731f0a1a6d204264677086db) and duration (0.388s)
 - 0.388s - lambda-function-url-HelloWorldFunction-sRQB00cHvXOP [HTTP: 200]
 - 0.021s - lambda-function-url-HelloWorldFunction-sRQB00cHvXOP
   - 0.223s - Initialization
   - 0.020s - Invocation
     - 0.019s - ## lambda handler
       - 0.018s - ## f
         - 0.000s - ## h
   - 0.000s - Overhead
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.