From 96554c82aba7fe527cdf6347d2cc45049ed11cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E4=BC=9F?= <305542043@qq.com> Date: Wed, 10 Apr 2019 15:56:48 +0800 Subject: [PATCH] Feature (#189) * Add xml comment * fix: LocalSegment relationship error when use Task.WhenAll --- build/common.props | 8 ++-- .../Tracing/Segments/SegmentSpan.cs | 6 +-- .../Tracing/LocalSegmentContextAccessor.cs | 47 +++++-------------- 3 files changed, 21 insertions(+), 40 deletions(-) diff --git a/build/common.props b/build/common.props index 280b2fe..caadea6 100644 --- a/build/common.props +++ b/build/common.props @@ -1,4 +1,4 @@ - + @@ -15,6 +15,8 @@ True True False - True + True + true + 1591 - \ No newline at end of file + diff --git a/src/SkyApm.Abstractions/Tracing/Segments/SegmentSpan.cs b/src/SkyApm.Abstractions/Tracing/Segments/SegmentSpan.cs index c8d64b9..6afba4c 100644 --- a/src/SkyApm.Abstractions/Tracing/Segments/SegmentSpan.cs +++ b/src/SkyApm.Abstractions/Tracing/Segments/SegmentSpan.cs @@ -1,4 +1,4 @@ -/* +/* * Licensed to the SkyAPM under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -42,8 +42,8 @@ namespace SkyApm.Tracing.Segments public SpanLayer SpanLayer { get; set; } + /// Limiting values. Please see or see public StringOrIntValue Component { get; set; } - public bool IsError { get; set; } public TagCollection Tags { get; } = new TagCollection(); @@ -187,4 +187,4 @@ namespace SkyApm.Tracing.Segments return new LogEvent("stack", value); } } -} \ No newline at end of file +} diff --git a/src/SkyApm.Core/Tracing/LocalSegmentContextAccessor.cs b/src/SkyApm.Core/Tracing/LocalSegmentContextAccessor.cs index 7142a12..1427b19 100644 --- a/src/SkyApm.Core/Tracing/LocalSegmentContextAccessor.cs +++ b/src/SkyApm.Core/Tracing/LocalSegmentContextAccessor.cs @@ -1,4 +1,4 @@ -/* +/* * Licensed to the SkyAPM under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -16,55 +16,34 @@ * */ -using System.Collections.Concurrent; -using System.Threading; using SkyApm.Tracing.Segments; +using System.Runtime.CompilerServices; +using System.Threading; namespace SkyApm.Tracing { public class LocalSegmentContextAccessor : ILocalSegmentContextAccessor { - private readonly AsyncLocal> _segmentContextStack = - new AsyncLocal>(); + private readonly ConditionalWeakTable _parent = new ConditionalWeakTable(); + private readonly AsyncLocal _segmentContext = new AsyncLocal(); public SegmentContext Context { - get - { - var stack = _segmentContextStack.Value; - if (stack == null) - { - return null; - } - stack.TryPeek(out var context); - return context; - } + get => _segmentContext.Value; set { - var stack = _segmentContextStack.Value; - if (stack == null) + var current = _segmentContext.Value; + if (value == null) { - if (value == null) return; - stack = new ConcurrentStack(); - stack.Push(value); - _segmentContextStack.Value = stack; + if (_parent.TryGetValue(current, out var parent)) + _segmentContext.Value = parent; } else { - if (value == null) - { - stack.TryPop(out _); - if (stack.IsEmpty) - { - _segmentContextStack.Value = null; - } - } - else - { - stack.Push(value); - } + _parent.Add(value, current); + _segmentContext.Value = value; } } } } -} \ No newline at end of file +} -- GitLab