'Can we assign an id for the AWS X-ray segment, which going to be autogenerated by AWS for a subsegment?

I send a segment with a subsegment to x-ray API. Subsegment is an s3 PutObject request. When X-ray receives this request, It automatically creates a segment for the s3 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?

Here is the raw data of the segment.

{
    "Id": "1-620bae7d-daf2e1177923ffb30e4c9729",
    "Duration": 5.869,
    "LimitExceeded": false,
    "Segments": [
        {
            "Id": "f0125b56d62b456b",
            "Document": {
                "id": "f0125b56d62b456b",
                "name": "raw-xray-dev",
                "start_time": 1644932733.217,
                "trace_id": "1-620bae7d-daf2e1177923ffb30e4c9729",
                "end_time": 1644932733.511,
                "aws": {
                    "ecs": {
                        "container": "xxxxxx"
                    },
                    "xray": {
                        "package": "aws-xray-sdk",
                        "sdk_version": "3.3.4",
                        "sdk": "X-Ray for Node.js"
                    }
                },
                "service": {
                    "name": "unknown",
                    "version": "unknown",
                    "runtime": "node",
                    "runtime_version": "v14.19.0"
                },
                "origin": "AWS::ECS::Container",
                "subsegments": [
                    {
                        "id": "2a3c3b42a0b5051e",
                        "name": "S3",
                        "start_time": 1644932733.223,
                        "end_time": 1644932733.303,
                        "http": {
                            "response": {
                                "status": 200
                            }
                        },
                        "aws": {
                            "retries": 0,
                            "bucket_name": "raw-attachment-dev",
                            "region": "ap-southeast-2",
                            "operation": "PutObject",
                            "request_id": "xxxxx",
                            "key": "xxxxxx",
                            "id_2": "xxxxxxxxxx",
                            "resource_names": [
                                "xxxxxx"
                            ]
                        },
                        "namespace": "aws"
                    }
                ]
            }
        },  
        {
            "Id": "386f836607911d57",
            "Document": {
                "id": "386f836607911d57",
                "name": "S3",
                "start_time": 1644932733.223,
                "trace_id": "1-620bae7d-daf2e1177923ffb30e4c9729",
                "end_time": 1644932733.303,
                "parent_id": "2a3c3b42a0b5051e",
                "inferred": true,
                "http": {
                    "response": {
                        "status": 200
                    }
                },
                "aws": {
                    "retries": 0,
                    "bucket_name": "raw-attachment-dev",
                    "region": "ap-southeast-2",
                    "operation": "PutObject",
                    "request_id": "xxxxxx",
                    "key": "xxxxxxxxx",
                    "id_2": "xxxxxxxxxxxxx",
                    "resource_names": [
                        "xxxxxxxxxx"
                    ]
                },
                "origin": "AWS::S3::Bucket"
            }
        }
    ]
}

The second segment is autogenerated by AWS X-ray. subsegment.id gives the value of "2a3c3b42a0b5051e", Which is not I am looking for. I need to know the segment Id ("386f836607911d57") before sending the request to API.

Can you help me if you have any possible solutions to this problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source