Search code examples
javagradleamazon-ecsaws-fargateaws-xray

ECS fargate doesn't show up in xray


So I have a kinesis consumer that is running in ECS fargate that I am trying to add on x-ray. I have added the x-ray side car to my CloudFormation for the task definition, and it shows up in the task and is running

      {
        "name": "xray-daemon",
        "Image": {************.dkr.ecr.us-east-1.amazonaws.com/xray-daemon},
        "cpu": 32,
        "memoryReservation": 256,
        "portMappings" : [
          {
            "containerPort": 2000,
            "protocol": "udp"
          }
        ]
      },

I then put before and after an SNS publish

AWSXRay.beginSubsegment("SNS Publish")
-- do the publish
AWSXRay.endSubsegment();

And still no luck.

Finally, I added the following in the start of my app to, which I beleive, is logging the entire ECS process to x-ray

    AWSXRayRecorderBuilder builder = AWSXRayRecorderBuilder.standard().withPlugin(new ECSPlugin())
    AWSXRay.setGlobalRecorder(builder.build())

So far, everything runs fine (consumer is unaffected, and running fine) but nothing is showing up in x-ray. Any ideas on what I might be missing?

Thanks


Solution

  • You need to wrap your kinesis consumer's code in a segment to be able to see any of the trace data. Segment will denote your consumer as a node in the X-Ray service map.

    https://github.com/aws/aws-xray-sdk-java#applications-not-using-javaxservlet-may-include-custom-interceptors-to-begin-and-end-trace-segments

    Use the AWSXRay.beginSegment and AWSXRay.endSegment APIs (similar to the subsegment APIs you're already using) to create a segment around the process. Subsegments require a segment to be present. You're probably getting x-ray ContextMissing errors in your log while trying to create subsegment.