Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default streaming strategy for Lambda should export segments immediately upon ending #327

Open
NathanielRN opened this issue Mar 7, 2022 · 1 comment

Comments

@NathanielRN
Copy link
Contributor

NathanielRN commented Mar 7, 2022

Description

In the X-Ray Java SDK, the default streaming strategy is to wait until there are 100 segments to send (export to the X-Ray Daemon for publishing) and then sending them all at once:

public class DefaultStreamingStrategy implements StreamingStrategy {
private static final int DEFAULT_MAX_SEGMENT_SIZE = 100;

This means that the streaming strategy for Lambda, which follows the recorder's streaming strategy, also batches segments:

if (recorder.getStreamingStrategy().requiresStreaming(currentSubsegment.getParentSegment())) {
recorder.getStreamingStrategy().streamSome(currentSubsegment.getParentSegment(), recorder.getEmitter());
}

This is a problem when instrumented Lambdas timeout and segments that have ended and are ready to be published aren't because they were waiting (for example) the 99th span to finish when the application timed out.

Users can already set the streaming strategy as so:

AWSXRay.getGlobalRecorder().setStreamingStrategy(new DefaultStreamingStrategy(0));

But this should be the default behavior for Lambda. We do this in other SDKs:

We do not do it in the following languages even though we should:

@NathanielRN NathanielRN changed the title Default streaming strategy should export segments immediately upon ending Default streaming strategy for Lambda should export segments immediately upon ending Mar 9, 2022
@Kurru
Copy link
Contributor

Kurru commented Jul 22, 2022

I'm not sure that is how this code behaves? I believe the DEFAULT_MAX_SEGMENT_SIZE = 100; refers to the maximum number of subsegments within a single segment.

This code (as I understand it), is specifically there to enable creation of extremely large segments, with potentially thousands of subsegments. The code counts up how many completed subsegments exist and once it crosses this threshold (100), it will send off a batch of subsegments to the x-ray daemon for forwarding to AWS.

Segments (as I have observed), are sent to the daemon immediately upon ending, and the daemon sends these to AWS typically within a second (though lambda may have different behavior).

For lambda timeouts specifically, I'm unsure of the behavior, though I have seen the retries appear later as 1 massive segment with all attempts in a single segment (might be mistaken, we don't use lambda much)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants