aws/aws-xray-sdk-java

Adding Subsegment.setShouldPropagate(boolean)

Kurru opened this issue · 1 comments

Kurru commented

Currently there exists Subsegment.shouldPropagate() which for regular subsegments always returns true and is only false for some use-cases of AWSXrayRecorder.beginSubsegment() (when there is no segment in the thread context).

SubsegmentImpl already returns shouldPropagate() based on a variable, though no-where sets this value to anything other than true.

My use-case is, I have a code path that generates thousands of xray subsegments (calls thousands of RPCs), which in aggregate (including downstream segments), exceeds the AWSXRay trace document size limit. I was looking for a way to suppress downstream x-ray segments in other APIs and this seemed to be named for this use-case.

Alternatively, I've been considering explicitly setting Segment.setSampled(false) to false once a certain number of subsegments are created, and then back to true before the Segment is completed. This would also allow me to stop generating downstream segments from my other apis (as we propagate sampled to our downstream).

Is there another alternative to help me manage segment generation/trace document size during massive fanout like this?

Control segment size by sampled flag is a good idea. Actually we are thinking about using sampled flag control the size of trace in other XRay feature since XRay trace quota has total size limit 500k bytes.

Alternatively you can use OpenTelemetry sdk instead of XRay sdk. There are several benefits for your requirement:

  1. OpenTelemetry span is independent with each other, spans maintain parent-child relationship by SpanContext, not like XRay SDK segment POJO contains a batch of child subsegments.
  2. OpenTelemetry provides Sampler API, you can implement a custom sampler to control the total size of trace(not span/segment).