Commit 96554c82 authored by 彭伟's avatar 彭伟 Committed by Lemon

Feature (#189)

* Add xml comment

* fix: LocalSegment relationship error when use Task.WhenAll
parent f67a8682
<Project> <Project>
<Import Project="sign.props" /> <Import Project="sign.props" />
<Import Project="version.props" /> <Import Project="version.props" />
<PropertyGroup> <PropertyGroup>
...@@ -16,5 +16,7 @@ ...@@ -16,5 +16,7 @@
<GenerateAssemblyProductAttribute>True</GenerateAssemblyProductAttribute> <GenerateAssemblyProductAttribute>True</GenerateAssemblyProductAttribute>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild> <GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1591</NoWarn>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
/* /*
* Licensed to the SkyAPM under one or more * Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
...@@ -42,8 +42,8 @@ namespace SkyApm.Tracing.Segments ...@@ -42,8 +42,8 @@ namespace SkyApm.Tracing.Segments
public SpanLayer SpanLayer { get; set; } public SpanLayer SpanLayer { get; set; }
/// <summary>Limiting values. Please see <see cref="Components" /> or see <seealso href="https://github.com/apache/incubator-skywalking/blob/master/oap-server/server-starter/src/main/resources/component-libraries.yml"/></summary>
public StringOrIntValue Component { get; set; } public StringOrIntValue Component { get; set; }
public bool IsError { get; set; } public bool IsError { get; set; }
public TagCollection Tags { get; } = new TagCollection(); public TagCollection Tags { get; } = new TagCollection();
......
/* /*
* Licensed to the SkyAPM under one or more * Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
...@@ -16,53 +16,32 @@ ...@@ -16,53 +16,32 @@
* *
*/ */
using System.Collections.Concurrent;
using System.Threading;
using SkyApm.Tracing.Segments; using SkyApm.Tracing.Segments;
using System.Runtime.CompilerServices;
using System.Threading;
namespace SkyApm.Tracing namespace SkyApm.Tracing
{ {
public class LocalSegmentContextAccessor : ILocalSegmentContextAccessor public class LocalSegmentContextAccessor : ILocalSegmentContextAccessor
{ {
private readonly AsyncLocal<ConcurrentStack<SegmentContext>> _segmentContextStack = private readonly ConditionalWeakTable<SegmentContext, SegmentContext> _parent = new ConditionalWeakTable<SegmentContext, SegmentContext>();
new AsyncLocal<ConcurrentStack<SegmentContext>>(); private readonly AsyncLocal<SegmentContext> _segmentContext = new AsyncLocal<SegmentContext>();
public SegmentContext Context public SegmentContext Context
{ {
get get => _segmentContext.Value;
{
var stack = _segmentContextStack.Value;
if (stack == null)
{
return null;
}
stack.TryPeek(out var context);
return context;
}
set set
{ {
var stack = _segmentContextStack.Value; var current = _segmentContext.Value;
if (stack == null)
{
if (value == null) return;
stack = new ConcurrentStack<SegmentContext>();
stack.Push(value);
_segmentContextStack.Value = stack;
}
else
{
if (value == null) if (value == null)
{ {
stack.TryPop(out _); if (_parent.TryGetValue(current, out var parent))
if (stack.IsEmpty) _segmentContext.Value = parent;
{
_segmentContextStack.Value = null;
}
} }
else else
{ {
stack.Push(value); _parent.Add(value, current);
} _segmentContext.Value = value;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment