From a2078f16dcf3fab78f2f2660ab9c095149175cba Mon Sep 17 00:00:00 2001 From: William Armiros Date: Tue, 3 Nov 2020 09:11:51 -0800 Subject: [PATCH] added context-free endSubsegment to AWSXRay class --- .../src/main/java/com/amazonaws/xray/AWSXRay.java | 6 +++++- .../src/main/java/com/amazonaws/xray/AWSXRayRecorder.java | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRay.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRay.java index 743c5a06..10da6ef7 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRay.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRay.java @@ -105,7 +105,7 @@ public static Segment beginSegment(String name, TraceID traceId, String parentId } /** - * @deprecated Use {@code AWSXray.getGlobalRecorder().beginNoOpSegment() }. + * @deprecated Use {@code AWSXRay.getGlobalRecorder().beginNoOpSegment() }. */ @Deprecated public static Segment beginDummySegment() { @@ -124,6 +124,10 @@ public static void endSubsegment() { globalRecorder.endSubsegment(); } + public static void endSubsegment(@Nullable Subsegment subsegment) { + globalRecorder.endSubsegment(subsegment); + } + @Nullable public String currentEntityId() { return globalRecorder.currentEntityId(); diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRayRecorder.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRayRecorder.java index db70ad24..6f7a4607 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRayRecorder.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRayRecorder.java @@ -554,12 +554,13 @@ public void endSegment() { } /** - * Ends the provided subsegment. This method doesn't touch context storage. + * Ends the provided subsegment. This method doesn't touch context storage and should be used when ending custom subsegments + * in asynchronous methods or other threads. * * @param subsegment * the subsegment to close. */ - public void endSubsegment(Subsegment subsegment) { + public void endSubsegment(@Nullable Subsegment subsegment) { if (subsegment == null) { logger.debug("No input subsegment to end. No-op."); return;