Remove no-op segments from context when closed
- Dominant language
- Java
- Stars
- 100
- Forks
- 100
- PR merge metrics
- No merged PRs in 30d
Description
## Backgroumd
When a customer calls `beginSegmentWithSampling` and the decision is made to not sample, a `NoOpSegment` is inserted into the context: https://github.com/aws/aws-xray-sdk-java/blob/d9d17ec980dce1c7e40a4b2e67cd5f76c5a36ea9/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRayRecorder.java#L431
However, when a customer calls `close` on that segment, it does not remove it from the context, leaving the stale no-op segment in context: https://github.com/aws/aws-xray-sdk-java/blob/5bab3e574f37b80b6b2628130eb7ea9b33336d4e/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/NoOpSegment.java#L391
This is distinct from `SegmentImpl.close()`, which does clear it from the context: https://github.com/aws/aws-xray-sdk-java/blob/5bab3e574f37b80b6b2628130eb7ea9b33336d4e/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/SegmentImpl.java#L200
## Solution
We should consider removing the no-op segment from the context when `closing` it.
Contributor guide
Assessment
This issue has not been assessed yet.