Comments (3)
Hello, I have a few questions that will hopefully help clarify where this issue is coming from:
- Is there any currently active context that should be passed in when configuring the xray_recorder? Are you running in Lambda?
- If you add another
xray_recorder.current_segment().trace_id
before the first call toupload_file
, does that trace ID match that of "test segment"? Can you also tryxray_recorder.get_trace_entity()
to see what the currently active entity (segment or subsegment) is? - Is this code snippet all in one place/function? Is there any additional code that is being executed between the block that throws an error and the one that doesn't?
from aws-xray-sdk-python.
Hello, to answer your questions
- There is no active context to pass to the xray_recorder. I discovered this issue when using xray sdk on glue pyshell and then recreated it locally.
- There is no additional code inbetween the lines. The code ran exactly as is.
Heres a snippet including more trace_id logs and the corresponding output
if __name__ == "__main__":
patch_all()
xray_recorder.configure(context_missing='LOG_ERROR', daemon_address='localhost:2000')
segment = xray_recorder.begin_segment('test segment')
logger.info(f'created segment trace_id:{segment.trace_id} ')
s3_resource = boto3.resource("s3")
logger.info(f'current trace entity trace_id: {xray_recorder.get_trace_entity().trace_id}')
# this give the error
logger.info(f'trace_id before error: {xray_recorder.current_segment().trace_id}')
s3_resource.Bucket('resultfiles-test' ).upload_file('hello_world.txt', 'hello_world.txt')
logger.info(f'trace_id after error: {xray_recorder.current_segment().trace_id}')
# this works
logger.info(f'trace_id before working: {xray_recorder.current_segment().trace_id}')
s3_resource.Bucket('resultfiles-test' ).put_object(Key='hello_world.txt', Body=b'hello world')
logger.info(f'trace_id after working: {xray_recorder.current_segment().trace_id}')
xray_recorder.end_segment()
output
INFO:aws_xray_sdk.core.patcher:successfully patched module botocore
INFO:aws_xray_sdk.core.patcher:successfully patched module sqlite3
INFO:aws_xray_sdk.core.sampling.sampler:No effective centralized sampling rule match. Fallback to local rules.
INFO:root:created segment trace_id:1-63d85b07-0a470e1a68d647efad69bce2
INFO:botocore.credentials:Found credentials in shared credentials file: ~/.aws/credentials
INFO:root:current trace entity trace_id: 1-63d85b07-0a470e1a68d647efad69bce2
INFO:root:trace_id before error: 1-63d85b07-0a470e1a68d647efad69bce2
ERROR:aws_xray_sdk.core.context:cannot find the current segment/subsegment, please make sure you have a segment open
WARNING:aws_xray_sdk.core.recorder:No segment found, cannot begin subsegment s3.
ERROR:aws_xray_sdk.core.context:cannot find the current segment/subsegment, please make sure you have a segment open
INFO:root:trace_id after error: 1-63d85b07-0a470e1a68d647efad69bce2
INFO:root:trace_id before working: 1-63d85b07-0a470e1a68d647efad69bce2
INFO:root:trace_id after working: 1-63d85b07-0a470e1a68d647efad69bce2
When I set the logging level to debug to see the segment sent, it includes the second working call to s3.
{
"id": "a69a1a6eb4e12c86",
"name": "test segment",
"start_time": 1675123698.393169,
"in_progress": false,
"aws": {
"xray": {
"sdk": "X-Ray for Python",
"sdk_version": "2.11.0"
}
},
"subsegments": [
{
"id": "1130954ac4c9383e",
"name": "s3",
"start_time": 1675123699.1555898,
"parent_id": "a69a1a6eb4e12c86",
"in_progress": false,
"http": {
"response": {
"status": 200
}
},
"aws": {
"operation": "PutObject",
"region": "us-east-1",
"request_id": "CTQFC52JXK7BED7F",
"id_2": "4lazYkItN+LCNrSfBTnved/tEByY50Od+KArL3cX5uWrx8BPHDXNMCnxOi/hhT4Tv9wd+aGbGdw=",
"key": "hello_world.txt",
"bucket_name": "resultfiles-test"
},
"trace_id": "1-63d85bf2-67e791f683029bb451728c4a",
"type": "subsegment",
"namespace": "aws",
"end_time": 1675123699.3337479
}
],
"trace_id": "1-63d85bf2-67e791f683029bb451728c4a",
"service": {
"runtime": "CPython",
"runtime_version": "3.9.8"
},
"end_time": 1675123699.335922
}
from aws-xray-sdk-python.
I discovered the issue can be resolved if I disable multi-threading on upload_file.
from aws-xray-sdk-python.
Related Issues (20)
- EKSPlugin HOT 1
- Very rare ReferenceError HOT 2
- Support for psycopg3 HOT 2
- Link a Textract async operation with downstream process HOT 1
- Current tox versions do not like how testenv.passenv is set
- aws_xray_sdk.core.exceptions.exceptions.SegmentNameMissingException: Segment name is required. HOT 1
- Using psycopg2 connection_factory throws exceptions HOT 4
- Documentation for patch_all HOT 2
- Sampling configuration should discuss DefaultSampler vs. LocalSampler HOT 1
- Flask middleware errors when an earlier Flask extension throws an exception in a before_request method HOT 1
- Patched DB cursor and template may record outside of XRayMiddleware HOT 2
- Segment not propgated when subsegment metadata is sufficiently long HOT 4
- sqlalchemy_core patch errors for unencoded special characters in db url HOT 1
- Error when using AsyncContext in python 3.11.5 HOT 3
- MongoDB AttributeError: 'NoneType' object has no attribute 'put_annotation'
- aws-xray-sdk-python compatibility with Python 3.12 HOT 9
- Fix docstring in Entity.close() HOT 1
- No supported for fastAPI, need to add middleware for fastapi HOT 1
- Incompatible with Pynamodb 6.x HOT 4
- trace simple websocket messages - python HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-xray-sdk-python.