awslabs / amazon-kinesis-client

Client library for Amazon Kinesis
Apache License 2.0
641 stars 465 forks source link

Feature request: add X-Ray support #310

Open ecerulm opened 6 years ago

ecerulm commented 6 years ago

I was trying to use KCL on a project where I have aws-xray-recorder-sdk-aws-sdk-instrumentor ,

KCL is raising SegmentNotFoundExceptions which I realized is because KCL is using it's own threads which is fine.

I thought I could just provide my own ExecutorService with new Worker.Builder().executorService(myExecutorServer).build() and call AWSXRay.beginSegment() before each Runnable but when I did I realized that there are other ExecutorServices that I can't customize. For example, LeaseCoordinator starts yet another.

So I think now it's not possible to use AWS X-Ray together with KCL, I mean I can just disable X-Ray globally and call addTracingHandler() for the other amazon clients I'm using. But then the work that KCL is doing won't be traced by X-Ray.

In my case AWS_TRACING_NAME is not a good fit since that is too global (I'm running code on apache storm).

For my particular use case I only need to set a segment name to use for all KCL calls so it would be ok (in my case) to have a method in KinesisClientLibConfiguration to set the tracing name and then the KCL would need to call AWSXRay.beginSegment(tracingName); AWSXRay.endSegment() in the task submitted to ExecutorServices.

ecerulm commented 6 years ago

I found a workaround that I described at https://stackoverflow.com/a/49280254/90580

Basically since it's possible to provide my own client instances of AmazonKinesis, AmazonCloudWatch and AmazonDynamoDB via Worker.Builder.kinesisClient(myClient), etc the problem is solved by adding a request handler to each of those client that invokes AWSXRay.beginSegment().

So

  final AmazonDynamoDB dynamoDBClient = AmazonDynamoDBClientBuilder
    .standard()
    .withRequestHandlers(new XRayTracingHandler("my-segment-listener"))
    .build();

where XRayTracingHandler is a custom class extending the Amazon's TracingHandler in which the beforeRequest() and afterResponse() are overrident to call beginSegment() and endSegment()

ecerulm commented 6 months ago

@zeynepsu , can you comment on how is this completed?

zeynepsu commented 6 months ago

Hello @ecerulm, I have added natively supporting X-Ray to our internal backlog and closed this issue since you mentioned you found a workaround. I can keep open and update this issue when we support X-Ray natively if that is something you are still interested in.

ecerulm commented 6 months ago

I can keep open and update this issue when we support X-Ray natively if that is something you are still interested in.

@zeynepsu , yes, please, that would be great.

2berk4 commented 1 month ago

Is there any update on this issue or any timeline on the native support for Kinesis with X-Ray?