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>
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
<GenerateAssemblyCompanyAttribute>True</GenerateAssemblyCompanyAttribute> <GenerateAssemblyCompanyAttribute>True</GenerateAssemblyCompanyAttribute>
<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>
\ No newline at end of file
/* /*
* 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();
...@@ -187,4 +187,4 @@ namespace SkyApm.Tracing.Segments ...@@ -187,4 +187,4 @@ namespace SkyApm.Tracing.Segments
return new LogEvent("stack", value); return new LogEvent("stack", value);
} }
} }
} }
\ No newline at end of file
/* /*
* 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,55 +16,34 @@ ...@@ -16,55 +16,34 @@
* *
*/ */
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)
{ {
if (value == null) return; if (_parent.TryGetValue(current, out var parent))
stack = new ConcurrentStack<SegmentContext>(); _segmentContext.Value = parent;
stack.Push(value);
_segmentContextStack.Value = stack;
} }
else else
{ {
if (value == null) _parent.Add(value, current);
{ _segmentContext.Value = value;
stack.TryPop(out _);
if (stack.IsEmpty)
{
_segmentContextStack.Value = null;
}
}
else
{
stack.Push(value);
}
} }
} }
} }
} }
} }
\ No newline at end of file
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