Closed YathuNK closed 1 year ago
I think segment ID generation is done by the SDK. I don't think we expose any API to modify the segment ID of the internal segment created by instrumentation. I think your best bet would be to probably add some delay in (dynamodb trigger) approach 2 that you mentioned so that you have parsed through the response you received from batch get traces
API.
Thanks @bhautikpip
I send a segment with a subsegment to x-ray API. Subsegment is an DynamoDB putItem request. When X-ray receives this request, It automatically creates a segment for the DynamoDB subsegment and assigns a random id. Is this possible to assign an id (or get to know the id) before sending the request to x-ray API?
This is the request I sent to x-ray API
aws xray put-trace-segments --trace-segment-documents "{\"trace_id\":\"1-620b79b7-ddce7ad676d9eb605e937952\",\"id\":\"e8760610e869f263\",\"start_time\":1644919222.813,\"name\":\"raw-xray-dev\",\"service\":{\"runtime\":\"node\",\"runtime_version\":\"v16.13.2\",\"version\":\"unknown\",\"name\":\"unknown\"},\"aws\":{\"ecs\":{\"container\":\"SL-YKalanantharasan\"},\"xray\":{\"sdk\":\"X-Ray for Node.js\",\"sdk_version\":\"3.3.4\",\"package\":\"aws-xray-sdk\"}},\"origin\":\"AWS::ECS::Container\",\"subsegments\":[{\"id\":\"2763c71e6e6227d2\",\"name\":\"dynamodb\",\"start_time\":1644919354.899,\"namespace\":\"aws\",\"aws\":{\"operation\":\"PutItem\",\"region\":\"ap-southeast-2\",\"request_id\":\"NELH0NTFAVHLQFAEFDJHSU9DJVV4KQNSO5AEMVJF66Q9ASUAAJG\",\"retries\":0,\"table_name\":\"raw-staging-dev\"},\"http\":{\"response\":{\"status\":200,\"content_length\":\"2\"}},\"end_time\":1644919355.785}],\"end_time\":1644919357.087}"
Here is the raw data of the segment.
The second segment is autogenerated by AWS X-ray. subsegment.id gives the value of "2763c71e6e6227d2", Which is not I am looking for. I need to know the segment Id ("1537a9f61a574777") before sending the request to API. So that I can add this id to DaynamoDB streams(lambda functions) as parent_id.
1) I can't use subsegment.addNewSubsegment() because DynamoDB streams are separate lambda functions. 2) I tried to use XRay.batchGetTraces() and loop through the results to find the id, but the DynamoDB trigger called before X-ray API process and save the segment trace.
Can you help me if you have any possible solutions to this problem?