public void EndSegment()

in sdk/src/Core/AWSXRayRecorderImpl.cs [194:232]


        public void EndSegment(DateTime? timestamp = null)
        {
#if !NETFRAMEWORK
            if (AWSXRayRecorder.IsLambda())
            {
                throw new UnsupportedOperationException("Cannot override Facade Segment. New segment not created.");
            }
#endif
            try
            {
                // If the request is not sampled, a segment will still be available in TraceContext.
                // Need to clean up the segment, but do not emit it.
                Segment segment = (Segment)TraceContext.GetEntity();

                if (!IsTracingDisabled())
                {
                    if (timestamp == null)
                    {
                        segment.SetEndTimeToNow();
                    }
                    else
                    {
                        segment.SetEndTime(timestamp.Value); // sets custom endtime
                    }

                    ProcessEndSegment(segment);
                }

                TraceContext.ClearEntity();
            }
            catch (EntityNotAvailableException e)
            {
                HandleEntityNotAvailableException(e, "Failed to end segment because cannot get the segment from trace context.");
            }
            catch (InvalidCastException e)
            {
                HandleEntityNotAvailableException(new EntityNotAvailableException("Failed to cast the entity to Segment.", e), "Failed to cast the entity to Segment.");
            }
        }