Skip to content

Commit

Permalink
Feature (SkyAPM#189)
Browse files Browse the repository at this point in the history
* Add xml comment

* fix: LocalSegment relationship error when use Task.WhenAll
  • Loading branch information
pengweiqhca authored and liuhaoyang committed Apr 10, 2019
1 parent f67a868 commit 96554c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 40 deletions.
8 changes: 5 additions & 3 deletions build/common.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project>
<Project>
<Import Project="sign.props" />
<Import Project="version.props" />
<PropertyGroup>
Expand All @@ -15,6 +15,8 @@
<GenerateAssemblyCompanyAttribute>True</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>True</GenerateAssemblyProductAttribute>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1591</NoWarn>
</PropertyGroup>
</Project>
</Project>
6 changes: 3 additions & 3 deletions src/SkyApm.Abstractions/Tracing/Segments/SegmentSpan.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -42,8 +42,8 @@ public class SegmentSpan

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 bool IsError { get; set; }
public TagCollection Tags { get; } = new TagCollection();

Expand Down Expand Up @@ -187,4 +187,4 @@ public static LogEvent ErrorStack(string value)
return new LogEvent("stack", value);
}
}
}
}
47 changes: 13 additions & 34 deletions src/SkyApm.Core/Tracing/LocalSegmentContextAccessor.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<ConcurrentStack<SegmentContext>> _segmentContextStack =
new AsyncLocal<ConcurrentStack<SegmentContext>>();
private readonly ConditionalWeakTable<SegmentContext, SegmentContext> _parent = new ConditionalWeakTable<SegmentContext, SegmentContext>();
private readonly AsyncLocal<SegmentContext> _segmentContext = new AsyncLocal<SegmentContext>();

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<SegmentContext>();
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;
}
}
}
}
}
}

0 comments on commit 96554c8

Please sign in to comment.