aws / aws/aws-xray-sdk-python

ERROR: cannot find the current segment/subsegment when segment is open and uploading file to s3.

Open
#377 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
338
Forks
147
PR merge metrics
No merged PRs in 30d

Description

Currently using python version 3.9, botocore version 1.29.50, aws_xray_sdk version 2.11.0

When I run the code snippet below I get an error saying there's no open segment for the calls the use upload file. The subsequent calls using put_object have no issues and show up in the segment data. Logging the trace_id was also successful.

```python
patch_all()
xray_recorder.configure(context_missing='LOG_ERROR', daemon_address='localhost:2000')
segment = xray_recorder.begin_segment('test segment')

s3_resource = boto3.resource("s3")

# These give the error
s3_resource.Bucket('resultfiles-test' ).upload_file('hello_world.txt', 'hello_world.txt')
logger.info(f'trace_id: {xray_recorder.current_segment().trace_id}')
s3_resource.Object('resultfiles-test', 'hello_world.txt').upload_file(Filename='hello_world.txt')
logger.info(f'trace_id: {xray_recorder.current_segment().trace_id}')

# These work
s3_resource.Bucket('resultfiles-test' ).put_object(Key='hello_world.txt', Body=b'hello world')
s3_resource.Object('resultfiles-test', 'hello_world.txt').put(Body=b'hello_world.txt')
with open('hello_world.txt', 'r') as f:
s3_resource.Object('resultfiles-test', 'hello_world.txt').put(Body=f.read())

xray_recorder.end_segment()
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.