From f66c6553ad31d8ca1fafbb3669c48a42c138e414 Mon Sep 17 00:00:00 2001 From: William Armiros <54150514+willarmiros@users.noreply.github.com> Date: Fri, 13 Nov 2020 11:50:22 -0800 Subject: [PATCH] added context-free endSubsegment to AWSXRay class (#229) --- .../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 792b9423..11fc9dc6 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 @@ -562,12 +562,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;