aws / aws/aws-xray-sdk-java

Default streaming strategy for Lambda should export segments immediately upon ending

Open
#327 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
100
Forks
100
PR merge metrics
No merged PRs in 30d

Description

## 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:

https://github.com/aws/aws-xray-sdk-java/blob/a2bc1ad7b8481d0f5090e460dcbdaaa7f77e5aa1/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/DefaultStreamingStrategy.java#L25-L27

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

https://github.com/aws/aws-xray-sdk-java/blob/a2bc1ad7b8481d0f5090e460dcbdaaa7f77e5aa1/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/contexts/LambdaSegmentContext.java#L126-L128

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:

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

But this should be the default behavior for Lambda. We do this in other SDKs:
* [X-Ray Python SDK Default Streaming Strategy Default of 0](https://github.com/aws/aws-xray-sdk-python/blob/f5f9c470b189bb34f31a1d0a28f497741132b7d2/aws_xray_sdk/core/recorder.py#L55-L61)
* [X-Ray JS SDK Default Streaming Strategy Default of 0](https://github.com/aws/aws-xray-sdk-node/blob/a9d0cf9cbd0328e40f30554f61b4bd5fac08bafc/packages/core/lib/env/aws_lambda.js#L25-L26)

We do _not_ do it in the following languages even though we should:
* [X-Ray Go Lambda Context](https://github.com/aws/aws-xray-sdk-go/blob/c4ccab1d3ca59f5ce66f3dab6522dc1fc4a490c7/xray/lambda.go)
* [X-Ray .NET Lambda Context](https://github.com/aws/aws-xray-sdk-dotnet/blob/d2b64125ecdd734af220795d5b102bd96b037981/sdk/src/Core/Internal/Context/LambdaContextContainer.netstandard.cs)
* [X-Ray Ruby Lambda Context](https://github.com/aws/aws-xray-sdk-ruby/blob/5d482e76d86b7610d5fe8e404c44cd0bce9e9547/lib/aws-xray-sdk/lambda/lambda_context.rb)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.