Commit b864df72 authored by lemon's avatar lemon Committed by 吴晟 Wu Sheng

Init trace interfaces (#13)

* Modify PackageTags

* Init commit

* Remove proto files reference

* Migrating some classes from Java

* Init DistributedTraceId

* Fix proto link

* Update .gitignore

* Init CarrierItem

* Refactor

* Init CarrierItem

* Init SkyWalking.NetworkProtocol.Trace

* Init ISpan

* Update project reference

* Init ContextSnaphot,TreacSegmentRef

* Add apache linence

* Refactor IContextCarrier

* Init AbstractTracingSpan

* Init AbstractTracingSpan

* Init traces

* Update appveyor.yml
parent 5ab58469
...@@ -7,17 +7,7 @@ environment: ...@@ -7,17 +7,7 @@ environment:
BUILDING_ON_PLATFORM: win BUILDING_ON_PLATFORM: win
BuildEnvironment: appveyor BuildEnvironment: appveyor
skip_tags: true skip_tags: true
skip_commits:
files:
- docs/*
- CONTIBUTING.md
- LICENSE
- README.md
- generate_protos.bat
- generate_protos_macos.sh
- generate_protos_linux.sh
- .travis.yml
- .gitignore
build_script: build_script:
- ps: ./build.ps1 - ps: ./build.ps1
test: off test: off
......
...@@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{613F0980-9 ...@@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{613F0980-9
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyWalking.Core.Tests", "test\SkyWalking.Core.Tests\SkyWalking.Core.Tests.csproj", "{3915A2C2-7174-4651-A4F1-D45CD109916A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyWalking.Core.Tests", "test\SkyWalking.Core.Tests\SkyWalking.Core.Tests.csproj", "{3915A2C2-7174-4651-A4F1-D45CD109916A}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyWalking.NetworkProtocol.Trace", "src\SkyWalking.NetworkProtocol.Trace\SkyWalking.NetworkProtocol.Trace.csproj", "{50BE8184-EC7A-4257-AF54-764C0E61276F}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -44,6 +46,10 @@ Global ...@@ -44,6 +46,10 @@ Global
{3915A2C2-7174-4651-A4F1-D45CD109916A}.Debug|Any CPU.Build.0 = Debug|Any CPU {3915A2C2-7174-4651-A4F1-D45CD109916A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3915A2C2-7174-4651-A4F1-D45CD109916A}.Release|Any CPU.ActiveCfg = Release|Any CPU {3915A2C2-7174-4651-A4F1-D45CD109916A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3915A2C2-7174-4651-A4F1-D45CD109916A}.Release|Any CPU.Build.0 = Release|Any CPU {3915A2C2-7174-4651-A4F1-D45CD109916A}.Release|Any CPU.Build.0 = Release|Any CPU
{50BE8184-EC7A-4257-AF54-764C0E61276F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50BE8184-EC7A-4257-AF54-764C0E61276F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50BE8184-EC7A-4257-AF54-764C0E61276F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50BE8184-EC7A-4257-AF54-764C0E61276F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
...@@ -53,6 +59,7 @@ Global ...@@ -53,6 +59,7 @@ Global
{C3860B5F-21D0-429F-8A00-B0C0F4573DF7} = {05BF0D4E-C824-4EC8-8330-36C1FC49910E} {C3860B5F-21D0-429F-8A00-B0C0F4573DF7} = {05BF0D4E-C824-4EC8-8330-36C1FC49910E}
{FD84A10C-C962-4AEA-BA06-86F08EB048E6} = {05BF0D4E-C824-4EC8-8330-36C1FC49910E} {FD84A10C-C962-4AEA-BA06-86F08EB048E6} = {05BF0D4E-C824-4EC8-8330-36C1FC49910E}
{3915A2C2-7174-4651-A4F1-D45CD109916A} = {613F0980-91ED-4064-8E8C-168582EF4AD7} {3915A2C2-7174-4651-A4F1-D45CD109916A} = {613F0980-91ED-4064-8E8C-168582EF4AD7}
{50BE8184-EC7A-4257-AF54-764C0E61276F} = {05BF0D4E-C824-4EC8-8330-36C1FC49910E}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94C0DA2C-CCCB-4314-93A2-9809B5DD0583} SolutionGuid = {94C0DA2C-CCCB-4314-93A2-9809B5DD0583}
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
*/ */
using System.Collections.Generic; using System.Collections.Generic;
using SkyWalking.Dictionary; using SkyWalking.Dictionarys;
namespace SkyWalking.Config namespace SkyWalking.Config
{ {
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Collections;
using System.Collections.Generic;
namespace SkyWalking.Context
{
public class CarrierItem : IEnumerable<CarrierItem>
{
private string _headKey;
private string _headValue;
private CarrierItem _next;
public virtual string HeadKey
{
get
{
return _headKey;
}
}
public virtual string HeadValue
{
get
{
return _headValue;
}
set
{
_headValue = value;
}
}
public CarrierItem(String headKey, String headValue)
{
_headKey = headKey;
_headValue = headValue;
_next = null;
}
public CarrierItem(String headKey, String headValue, CarrierItem next)
{
_headKey = headKey;
_headValue = headValue;
_next = next;
}
public IEnumerator<CarrierItem> GetEnumerator()
{
return new Enumerator(this);
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
private class Enumerator : IEnumerator<CarrierItem>
{
private CarrierItem _head;
private CarrierItem _current;
public CarrierItem Current => _current;
object IEnumerator.Current => _current;
public Enumerator(CarrierItem head)
{
_head = head;
_current = head;
}
public void Dispose()
{
}
public bool MoveNext()
{
var next = _current._next;
if (next == null)
{
return false;
}
_current = next;
return true;
}
public void Reset()
{
_current = _head;
}
}
}
}
using System; /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Threading; using System.Threading;
namespace SkyWalking.Context namespace SkyWalking.Context
...@@ -24,5 +42,10 @@ namespace SkyWalking.Context ...@@ -24,5 +42,10 @@ namespace SkyWalking.Context
} }
} }
public static IContextSnapshot Capture()
{
return null;
}
} }
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.Collections.Generic;
using SkyWalking.Context.Ids;
namespace SkyWalking.Context
{
public interface IContextCarrier
{
DistributedTraceId DistributedTraceId { get; }
int EntryApplicationInstanceId { get; set; }
string EntryOperationName { get; set; }
int ParentApplicationInstanceId { get; set; }
string ParentOperationName { get; set; }
string PeerHost { get; set; }
int SpanId { get; set; }
ID TraceSegmentId { get; set; }
bool IsValid { get; }
IContextCarrier Deserialize(string text);
string Serialize();
CarrierItem Items { get; }
void SetDistributedTraceIds(IEnumerable<DistributedTraceId> distributedTraceIds);
}
}
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using SkyWalking.Context.Ids;
namespace SkyWalking.Context
{
public interface IContextSnapshot
{
string EntryOperationName { get; set; }
string ParentOperationName { get; set; }
DistributedTraceId DistributedTraceId { get; }
int EntryApplicationInstanceId { get; set; }
int SpanId { get; }
bool IsFromCurrent { get; }
bool IsValid { get; }
ID TraceSegmentId { get; }
int EntryOperationId { set; }
int ParentOperationId { set; }
}
}
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
namespace SkyWalking.Context
{
public interface IInjectable
{
IContextCarrier GetCarrier();
/// <summary>
/// @return peer, represent ipv4, ipv6, hostname, or cluster addresses list.
/// </summary>
/// <returns></returns>
String GetPeer();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace SkyWalking.Context
{
interface ITracingContextListener
{
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.Collections.Generic;
namespace SkyWalking.Context.Ids
{
public interface IDistributedTraceIdCollection
{
IReadOnlyList<DistributedTraceId> GetRelatedGlobalTraces();
void Append(DistributedTraceId distributedTraceId);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using SkyWalking.Context.Trace;
namespace SkyWalking.Context.Tag
{
public abstract class AbstractTag<T>
{
public AbstractTag(string tagKey)
{
Key = tagKey;
}
protected abstract void Set(ISpan span, T tagValue);
/**
* @return the key of this tag.
*/
public string Key { get; protected set; }
}
}
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Collections.Generic;
using SkyWalking.Dictionarys;
using SkyWalking.NetworkProtocol;
using SkyWalking.NetworkProtocol.Trace;
using System.Linq;
namespace SkyWalking.Context.Trace
{
/// <summary>
/// The <code>AbstractTracingSpan</code> represents a group of {@link ISpan} implementations, which belongs a real distributed trace.
/// </summary>
public abstract class AbstractTracingSpan : ISpan
{
protected int _spanId;
protected int _parnetSpanId;
protected Dictionary<string, string> _tags;
protected string _operationName;
protected int _operationId;
protected SpanLayer? _layer;
/// <summary>
/// The start time of this Span.
/// </summary>
protected long _startTime;
/// <summary>
/// The end time of this Span.
/// </summary>
protected long _endTime;
protected bool _errorOccurred = false;
protected int _componentId = 0;
protected string _componentName;
/// <summary>
/// Log is a concept from OpenTracing spec. <p> {@see https://github.com/opentracing/specification/blob/master/specification.md#log-structured-data}
/// </summary>
protected ICollection<LogDataEntity> _logs;
/// <summary>
/// The refs of parent trace segments, except the primary one. For most RPC call, {@link #refs} contains only one
/// element, but if this segment is a start span of batch process, the segment faces multi parents, at this moment,
/// we use this {@link #refs} to link them.
/// </summary>
protected ICollection<ITraceSegmentRef> _refs;
protected AbstractTracingSpan(int spanId, int parentSpanId, string operationName)
{
_operationName = operationName;
_operationId = DictionaryUtil.NullValue;
_spanId = spanId;
_parnetSpanId = parentSpanId;
}
protected AbstractTracingSpan(int spanId, int parentSpanId, int operationId)
{
_operationName = null;
_operationId = operationId;
_spanId = spanId;
_parnetSpanId = parentSpanId;
}
public abstract bool IsEntry { get; }
public abstract bool IsExit { get; }
public virtual int SpanId => _spanId;
public virtual string OperationName
{
get
{
return _operationName;
}
set
{
_operationName = value;
_operationId = DictionaryUtil.NullValue;
}
}
public virtual int OperationId
{
get
{
return _operationId;
}
set
{
_operationId = value;
_operationName = null;
}
}
public virtual ISpan SetComponent(IComponent component)
{
_componentId = component.Id;
return this;
}
public virtual ISpan SetComponent(string componentName)
{
_componentName = componentName;
return this;
}
public virtual ISpan Tag(string key, string value)
{
if (_tags == null)
{
_tags = new Dictionary<string, string>();
}
_tags.Add(key, value);
return this;
}
public virtual ISpan SetLayer(SpanLayer layer)
{
_layer = layer;
return this;
}
/// <summary>
/// Record an exception event of the current walltime timestamp.
/// </summary>
public virtual ISpan Log(Exception exception)
{
EnsureLogs();
_logs.Add(new LogDataEntity.Builder()
.Add("event", "error")
.Add("error.kind", exception.GetType().FullName)
.Add("message", exception.Message)
.Add("stack", exception.StackTrace)
.Build(DateTime.UtcNow.GetTimeMillis()));
return this;
}
public virtual ISpan ErrorOccurred()
{
_errorOccurred = true;
return this;
}
public virtual ISpan Log(long timestamp, IDictionary<string, object> events)
{
EnsureLogs();
LogDataEntity.Builder builder = new LogDataEntity.Builder();
foreach (var @event in events)
{
builder.Add(@event.Key, @event.Value.ToString());
}
_logs.Add(builder.Build(timestamp));
return this;
}
public virtual ISpan Start()
{
_startTime = DateTime.UtcNow.GetTimeMillis();
return this;
}
public virtual ISpan Start(long timestamp)
{
_startTime = timestamp;
return this;
}
public virtual void Ref(ITraceSegmentRef traceSegmentRef)
{
if (_refs == null)
{
_refs = new List<ITraceSegmentRef>();
}
if (!_refs.Contains(traceSegmentRef))
{
_refs.Add(traceSegmentRef);
}
}
/// <summary>
/// Finish the active Span. When it is finished, it will be archived by the given {@link TraceSegment}, which owners it
/// </summary>
/// <param name="owner"></param>
/// <returns></returns>
public virtual bool Finish(ITraceSegment owner)
{
_endTime = DateTime.UtcNow.GetTimeMillis();
owner.Archive(this);
return true;
}
public virtual SpanObject Transform()
{
SpanObject spanObject = new SpanObject();
spanObject.SpanId = _spanId;
spanObject.ParentSpanId = _parnetSpanId;
spanObject.StartTime = _startTime;
spanObject.EndTime = _endTime;
if (_operationId != DictionaryUtil.NullValue)
{
spanObject.OperationNameId = _operationId;
}
else
{
spanObject.OperationName = _operationName;
}
if (IsEntry)
{
spanObject.SpanType = SpanType.Entry;
}
else if (IsExit)
{
spanObject.SpanType = SpanType.Exit;
}
else
{
spanObject.SpanType = SpanType.Local;
}
if (_layer.HasValue)
{
spanObject.SpanLayer = (NetworkProtocol.SpanLayer)((int)_layer.Value);
}
if (_componentId != DictionaryUtil.NullValue)
{
spanObject.ComponentId = _componentId;
}
else
{
spanObject.Component = _componentName;
}
spanObject.IsError = _errorOccurred;
if (_tags != null)
{
spanObject.Tags.Add(_tags.Select(x => new KeyWithStringValue { Key = x.Key, Value = x.Value }));
}
if (_logs != null)
{
spanObject.Logs.Add(_logs.Select(x => x.Transform()));
}
if (_refs != null)
{
spanObject.Refs.Add(_refs.Select(x => x.Transform()));
}
return spanObject;
}
private void EnsureLogs()
{
if (_logs == null)
{
_logs = new LinkedList<LogDataEntity>();
}
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Collections.Generic;
using System.Text;
using SkyWalking.NetworkProtocol.Trace;
namespace SkyWalking.Context.Trace
{
/// <summary>
/// The <code>AbstractSpan</code> represents the span's skeleton, which contains all open methods.
/// </summary>
public interface ISpan
{
/// <summary>
/// Set the component id, which defines in ComponentsDefine
/// </summary>
/// <param name="component"></param>
/// <returns></returns>
ISpan SetComponent(IComponent component);
/// <summary>
/// Only use this method in explicit instrumentation, like opentracing-skywalking-bridge. It it higher recommend
/// don't use this for performance consideration.
/// </summary>
/// <param name="componentName"></param>
/// <returns></returns>
ISpan SetComponent(string componentName);
/// <summary>
/// Set a key:value tag on the Span.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
ISpan Tag(string key, string value);
ISpan SetLayer(SpanLayer layer);
/// <summary>
/// Record an exception event of the current walltime timestamp.
/// </summary>
/// <param name="exception"></param>
/// <returns></returns>
ISpan Log(Exception exception);
ISpan ErrorOccurred();
bool IsEntry { get; }
bool IsExit { get; }
ISpan Log(long timestamp, IDictionary<string, object> @event);
ISpan Start();
int SpanId { get; }
string OperationName { get; set; }
int OperationId { get; set; }
ISpan Start(long timestamp);
void Ref(ITraceSegmentRef traceSegmentRef);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.Collections.Generic;
using SkyWalking.Context.Ids;
using SkyWalking.NetworkProtocol;
namespace SkyWalking.Context.Trace
{
public interface ITraceSegment
{
void Archive(AbstractTracingSpan finishedSpan);
ITraceSegment Finish(bool isSizeLimited);
int ApplicationId { get; }
int ApplicationInstanceId { get; }
IEnumerable<ITraceSegmentRef> Refs { get; }
IEnumerable<DistributedTraceId> RelatedGlobalTraces { get; }
ID TraceSegmentId { get; }
bool HasRef { get; }
bool IsIgnore { get; set; }
bool IsSingleSpanSegment { get; }
void Ref(ITraceSegmentRef refSegment);
void RelatedGlobalTrace(DistributedTraceId distributedTraceId);
UpstreamSegment Transform();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using SkyWalking.NetworkProtocol;
namespace SkyWalking.Context.Trace
{
public interface ITraceSegmentRef : IEquatable<ITraceSegmentRef>
{
string EntryOperationName { get; }
int EntryOperationId { get; }
int EntryApplicationInstance { get; }
TraceSegmentReference Transform();
}
}
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace SkyWalking.Context.Trace
{
public interface IWithPeerInfo
{
int PeerId { get; }
string Peer { get; }
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.Collections.Generic;
using System.Collections.ObjectModel;
using SkyWalking.NetworkProtocol;
namespace SkyWalking.Context.Trace
{
public class LogDataEntity
{
private long _timestamp = 0;
private Dictionary<string, string> _logs;
private LogDataEntity(long timestamp,Dictionary<string,string> logs)
{
_timestamp = timestamp;
_logs = logs;
}
public IReadOnlyDictionary<string,string> Logs
{
get
{
return new ReadOnlyDictionary<string, string>(_logs);
}
}
public class Builder
{
private Dictionary<string, string> _logs;
public Builder()
{
_logs = new Dictionary<string, string>();
}
public Builder Add(IDictionary<string, string> fields)
{
foreach (var field in fields)
_logs.Add(field.Key, field.Value);
return this;
}
public Builder Add(string key,string value)
{
_logs.Add(key, value);
return this;
}
public LogDataEntity Build(long timestamp)
{
return new LogDataEntity(timestamp, _logs);
}
}
public LogMessage Transform()
{
LogMessage logMessage = new LogMessage();
logMessage.Time = _timestamp;
foreach(var log in _logs)
{
logMessage.Data.Add(new KeyWithStringValue { Key = log.Key, Value = log.Value });
}
return logMessage;
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace SkyWalking.Context.Trace
{
public enum SegmentRefType
{
CrossProcess,
CrossThread
}
}
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace SkyWalking.Context.Trace
{
public enum SpanLayer
{
DB = 1,
RPC_FRAMEWORK = 2,
HTTP = 3,
MQ = 4,
CACHE = 5
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace SkyWalking.Context.Trace
{
public static class SpanLayereExtensions
{
public static void AsDB(this ISpan span)
{
span.SetLayer(SpanLayer.DB);
}
public static void AsCache(this ISpan span)
{
span.SetLayer(SpanLayer.CACHE);
}
public static void AsRPCFramework(this ISpan span)
{
span.SetLayer(SpanLayer.RPC_FRAMEWORK);
}
public static void AsHttp(this ISpan span)
{
span.SetLayer(SpanLayer.HTTP);
}
public static void AsMQ(this ISpan span)
{
span.SetLayer(SpanLayer.MQ);
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace SkyWalking.Context.Trace
{
public abstract class StackBasedTracingSpan : AbstractTracingSpan
{
protected int _stackDepth;
protected StackBasedTracingSpan(int spanId, int parentSpanId, string operationName)
: base(spanId, parentSpanId, operationName)
{
_stackDepth = 0;
}
protected StackBasedTracingSpan(int spanId, int parentSpanId, int operationId)
: base(spanId, parentSpanId, operationId)
{
_stackDepth = 0;
}
}
}
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
*/ */
namespace SkyWalking.Dictionary namespace SkyWalking.Dictionarys
{ {
public static class DictionaryUtil public static class DictionaryUtil
{ {
......
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" /> <Import Project="..\..\build\common.props" />
<PropertyGroup> <PropertyGroup>
<Description>SkyWalking Core abstractions and interfaces for apm agent.</Description> <Description>SkyWalking Core abstractions and interfaces for apm agent.</Description>
<AssemblyTitle>SkyWalking.Abstractions</AssemblyTitle> <AssemblyTitle>SkyWalking.Abstractions</AssemblyTitle>
...@@ -9,12 +7,12 @@ ...@@ -9,12 +7,12 @@
<AssemblyName>SkyWalking.Abstractions</AssemblyName> <AssemblyName>SkyWalking.Abstractions</AssemblyName>
<PackageId>SkyWalking.Abstractions</PackageId> <PackageId>SkyWalking.Abstractions</PackageId>
<PackageTags>SkyWalking;APM</PackageTags> <PackageTags>SkyWalking;APM</PackageTags>
<PackageReleaseNotes></PackageReleaseNotes> <PackageReleaseNotes>
</PackageReleaseNotes>
<RootNamespace>SkyWalking</RootNamespace> <RootNamespace>SkyWalking</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SkyWalking.NetworkProtocol.Trace\SkyWalking.NetworkProtocol.Trace.csproj" />
<ProjectReference Include="..\SkyWalking.NetworkProtocol\SkyWalking.NetworkProtocol.csproj" /> <ProjectReference Include="..\SkyWalking.NetworkProtocol\SkyWalking.NetworkProtocol.csproj" />
</ItemGroup> </ItemGroup>
</Project>
</Project> \ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace SkyWalking.Context
{
public class CarrierItemHead : CarrierItem
{
public CarrierItemHead(CarrierItem next) : base(string.Empty, string.Empty, next)
{
}
}
}
using System.Collections.Generic;
using System.Linq;
using SkyWalking.Context.Ids;
using SkyWalking.Dictionarys;
namespace SkyWalking.Context
{
public class ContextCarrier : IContextCarrier
{
private ID _traceSegmentId;
/// <summary>
/// id of parent span
/// </summary>
private int _spanId = -1;
/// <summary>
/// id of parent application instance
/// </summary>
private int _parentApplicationInstanceId = DictionaryUtil.NullValue;
/// <summary>
/// id of first application instance in this distributed trace
/// </summary>
private int _entryApplicationInstanceId = DictionaryUtil.NullValue;
/// <summary>
/// peer(ipv4/ipv6/hostname + port) of the server , from client side .
/// </summary>
private string _peerHost;
/// <summary>
/// Operation/Service name of the first one in this distributed trace .
/// </summary>
private string _entryOperationName;
/// <summary>
/// Operation/Service name of the parent one in this distributed trace .
/// </summary>
private string _parentOPerationName;
private DistributedTraceId _primaryDistributedTraceId;
public DistributedTraceId DistributedTraceId
{
get { return _primaryDistributedTraceId; }
}
public int EntryApplicationInstanceId
{
get { return _entryApplicationInstanceId; }
set { _entryApplicationInstanceId = value; }
}
public string EntryOperationName
{
get { return _entryOperationName; }
set { _entryOperationName = "#" + value; }
}
public int ParentApplicationInstanceId
{
get { return _parentApplicationInstanceId; }
set { _parentApplicationInstanceId = value; }
}
public string ParentOperationName
{
get { return _parentOPerationName; }
set { _parentOPerationName = "#" + value; }
}
public string PeerHost
{
get { return _peerHost; }
set { _peerHost = value; }
}
public int SpanId
{
get { return _spanId; }
set { _spanId = value; }
}
public ID TraceSegmentId
{
get { return _traceSegmentId; }
set { _traceSegmentId = value; }
}
public bool IsValid
{
get
{
return _traceSegmentId != null
&& _traceSegmentId.IsValid
&& _spanId > -1
&& _parentApplicationInstanceId != DictionaryUtil.NullValue
&& _entryApplicationInstanceId != DictionaryUtil.NullValue
&& string.IsNullOrEmpty(_parentOPerationName)
&& string.IsNullOrEmpty(_entryOperationName)
&& _primaryDistributedTraceId != null;
}
}
public IContextCarrier Deserialize(string text)
{
string[] parts = text?.Split("|".ToCharArray(), 8);
if (parts?.Length == 8)
{
_traceSegmentId = new ID(parts[0]);
_spanId = int.Parse(parts[1]);
_parentApplicationInstanceId = int.Parse(parts[2]);
_entryApplicationInstanceId = int.Parse(parts[3]);
_peerHost = parts[4];
_entryOperationName = parts[5];
_parentOPerationName = parts[6];
_primaryDistributedTraceId = new PropagatedTraceId(parts[7]);
}
return this;
}
public string Serialize()
{
if (!IsValid)
{
return string.Empty;
}
return string.Join("|",
TraceSegmentId.Encode,
SpanId.ToString(),
ParentApplicationInstanceId.ToString(),
EntryApplicationInstanceId.ToString(),
PeerHost,
EntryOperationName,
ParentOperationName,
PrimaryDistributedTraceId.Encode);
}
public DistributedTraceId PrimaryDistributedTraceId
{
get { return _primaryDistributedTraceId; }
}
public CarrierItem Items
{
get
{
SW3CarrierItem carrierItem = new SW3CarrierItem(this, null);
CarrierItemHead head = new CarrierItemHead(carrierItem);
return head;
}
}
public void SetDistributedTraceIds(IEnumerable<DistributedTraceId> distributedTraceIds)
{
_primaryDistributedTraceId = distributedTraceIds.FirstOrDefault();
}
}
}
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.Collections.Generic;
using System.Linq;
using SkyWalking.Context.Ids;
using SkyWalking.Dictionarys;
namespace SkyWalking.Context
{
public class ContextSnapshot : IContextSnapshot
{
/// <summary>
/// Trace Segment Id of the parent trace segment
/// </summary>
private ID _traceSegmentId;
/// <summary>
/// span id of the parent span , in parent trace segment
/// </summary>
private int _spanId = -1;
private string _entryOperationName;
private string _parentOperationName;
private DistributedTraceId _primaryDistributedTraceId;
private int _entryApplicationInstanceId = DictionaryUtil.NullValue;
public ContextSnapshot(ID traceSegmentId, int spanId, List<DistributedTraceId> distributedTraceIds)
{
_traceSegmentId = traceSegmentId;
_spanId = spanId;
_primaryDistributedTraceId = distributedTraceIds?.FirstOrDefault();
}
public string EntryOperationName
{
get { return _entryOperationName; }
set { _entryOperationName = "#" + value; }
}
public string ParentOperationName
{
get { return _parentOperationName; }
set { _parentOperationName = "#" + value; }
}
public DistributedTraceId DistributedTraceId
{
get { return _primaryDistributedTraceId; }
}
public int EntryApplicationInstanceId
{
get { return _entryApplicationInstanceId; }
set { _entryApplicationInstanceId = value; }
}
public int SpanId
{
get { return _spanId; }
}
public bool IsFromCurrent
{
get { return _traceSegmentId.Equals(ContextManager.Capture().TraceSegmentId); }
}
public bool IsValid
{
get
{
return _traceSegmentId != null
&& _spanId > -1
&& _entryApplicationInstanceId != DictionaryUtil.NullValue
&& _primaryDistributedTraceId != null
&& string.IsNullOrEmpty(_entryOperationName)
&& string.IsNullOrEmpty(_parentOperationName);
}
}
public ID TraceSegmentId
{
get { return _traceSegmentId; }
}
public int EntryOperationId
{
set { _entryOperationName = value + ""; }
}
public int ParentOperationId
{
set { _parentOperationName = value + ""; }
}
}
}
\ No newline at end of file
...@@ -20,11 +20,11 @@ using System.Collections.Generic; ...@@ -20,11 +20,11 @@ using System.Collections.Generic;
namespace SkyWalking.Context.Ids namespace SkyWalking.Context.Ids
{ {
public class DistributedTraceIds public class DistributedTraceIdCollection : IDistributedTraceIdCollection
{ {
private readonly List<DistributedTraceId> _relatedGlobalTraces; private readonly List<DistributedTraceId> _relatedGlobalTraces;
public DistributedTraceIds() public DistributedTraceIdCollection()
{ {
_relatedGlobalTraces = new List<DistributedTraceId>(); _relatedGlobalTraces = new List<DistributedTraceId>();
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
using System; using System;
using System.Threading; using System.Threading;
using SkyWalking.Config; using SkyWalking.Config;
using SkyWalking.Dictionary; using SkyWalking.Dictionarys;
namespace SkyWalking.Context.Ids namespace SkyWalking.Context.Ids
{ {
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
namespace SkyWalking.Context
{
public class SW3CarrierItem : CarrierItem
{
public const String HEADER_NAME = "sw3";
private IContextCarrier _carrier;
public SW3CarrierItem(IContextCarrier carrier, CarrierItem next)
: base(HEADER_NAME, carrier.Serialize(), next)
{
_carrier = carrier;
}
public override string HeadValue { get => base.HeadValue; set => _carrier.Deserialize(value); }
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using SkyWalking.Context.Trace;
namespace SkyWalking.Context.Tag
{
public class StringTag : AbstractTag<string>
{
public StringTag(string tagKey) : base(tagKey)
{
}
protected override void Set(ISpan span, string tagValue)
{
span.Tag(Key, tagValue);
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace SkyWalking.Context.Tag
{
/// <summary>
/// The span tags are supported by sky-walking engine.
/// As default, all tags will be stored, but these ones have particular meanings.
/// </summary>
public static class Tags
{
public static StringTag URL = new StringTag("url");
/**
* STATUS_CODE records the http status code of the response.
*/
public static StringTag STATUS_CODE = new StringTag("status_code");
/**
* DB_TYPE records database type, such as sql, redis, cassandra and so on.
*/
public static StringTag DB_TYPE = new StringTag("db.type");
/**
* DB_INSTANCE records database instance name.
*/
public static StringTag DB_INSTANCE = new StringTag("db.instance");
/**
* DB_STATEMENT records the sql statement of the database access.
*/
public static StringTag DB_STATEMENT = new StringTag("db.statement");
/**
* DB_BIND_VARIABLES records the bind variables of sql statement.
*/
public static StringTag DB_BIND_VARIABLES = new StringTag("db.bind_vars");
/**
* MQ_BROKER records the broker address of message-middleware
*/
public static StringTag MQ_BROKER = new StringTag("mq.broker");
/**
* MQ_TOPIC records the topic name of message-middleware
*/
public static StringTag MQ_TOPIC = new StringTag("mq.topic");
public static class HTTP
{
public static readonly StringTag METHOD = new StringTag("http.method");
}
}
}
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using SkyWalking.Dictionarys;
using SkyWalking.NetworkProtocol.Trace;
namespace SkyWalking.Context.Trace
{
public class EntrySpan : StackBasedTracingSpan
{
private int _currentMaxDepth;
public EntrySpan(int spanId, int parentSpanId, string operationName)
: base(spanId, parentSpanId, operationName)
{
_stackDepth = 0;
}
public EntrySpan(int spanId, int parentSpanId, int operationId)
: base(spanId, parentSpanId, operationId)
{
_stackDepth = 0;
}
public override bool IsEntry => true;
public override bool IsExit => false;
public override ISpan Start()
{
if ((_currentMaxDepth = ++_stackDepth) == 1)
{
base.Start();
}
ClearWhenRestart();
return this;
}
public override ISpan Tag(string key, string value)
{
if (_stackDepth == _currentMaxDepth)
{
base.Tag(key, value);
}
return this;
}
public override ISpan SetLayer(SpanLayer layer)
{
if (_stackDepth == _currentMaxDepth)
{
return base.SetLayer(layer);
}
return this;
}
public override ISpan SetComponent(IComponent component)
{
if (_stackDepth == _currentMaxDepth)
{
return base.SetComponent(component);
}
return this;
}
public override ISpan SetComponent(string componentName)
{
if (_stackDepth == _currentMaxDepth)
{
return base.SetComponent(componentName);
}
return this;
}
public override string OperationName
{
get
{
return base.OperationName;
}
set
{
if (_stackDepth == _currentMaxDepth)
{
base.OperationName = value;
}
}
}
public override int OperationId
{
get
{
return base.OperationId;
}
set
{
if (_stackDepth == _currentMaxDepth)
{
base.OperationId = value;
}
}
}
private void ClearWhenRestart()
{
_componentId = DictionaryUtil.NullValue;
_componentName = null;
_layer = null;
_logs = null;
_tags = null;
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Collections.Generic;
using System.Text;
using SkyWalking.Dictionarys;
using SkyWalking.NetworkProtocol;
using SkyWalking.NetworkProtocol.Trace;
namespace SkyWalking.Context.Trace
{
public class ExitSpan : StackBasedTracingSpan, IWithPeerInfo
{
private string _peer;
private int _peerId;
protected ExitSpan(int spanId, int parentSpanId, string operationName,string peer) : base(spanId, parentSpanId, operationName)
{
_peer = peer;
}
protected ExitSpan(int spanId, int parentSpanId, int operationId,int peerId) : base(spanId, parentSpanId, operationId)
{
_peerId = peerId;
}
public override bool IsEntry => false;
public override bool IsExit => true;
public int PeerId => _peerId;
public string Peer => _peer;
public override ISpan Start()
{
if (++_stackDepth == 1)
{
base.Start();
}
return base.Start();
}
public override ISpan Tag(string key, string value)
{
if (_stackDepth == 1)
{
base.Tag(key, value);
}
return this;
}
public override ISpan SetLayer(SpanLayer layer)
{
if (_stackDepth == 1)
{
return base.SetLayer(layer);
}
return this;
}
public override ISpan SetComponent(IComponent component)
{
if (_stackDepth == 1)
{
return base.SetComponent(component);
}
return this;
}
public override ISpan SetComponent(string componentName)
{
if (_stackDepth == 1)
{
return base.SetComponent(componentName);
}
return this;
}
public override string OperationName
{
get
{
return base.OperationName;
}
set
{
if (_stackDepth == 1)
{
base.OperationName = value;
}
}
}
public override int OperationId
{
get
{
return base.OperationId;
}
set
{
if (_stackDepth == 1)
{
base.OperationId = value;
}
}
}
public override SpanObject Transform()
{
var spanObject= base.Transform();
if (_peerId != DictionaryUtil.NullValue)
{
spanObject.PeerId = _peerId;
}
else
{
spanObject.Peer = _peer;
}
return spanObject;
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace SkyWalking.Context.Trace
{
public class LocalSpan : StackBasedTracingSpan
{
protected LocalSpan(int spanId, int parentSpanId, string operationName) : base(spanId, parentSpanId, operationName)
{
}
protected LocalSpan(int spanId, int parentSpanId, int operationId) : base(spanId, parentSpanId, operationId)
{
}
public override bool IsEntry => false;
public override bool IsExit => false;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
namespace SkyWalking.Context.Trace
{
public class NoopExitSpan : NoopSpan, IWithPeerInfo
{
public int PeerId => throw new NotImplementedException();
public string Peer => throw new NotImplementedException();
private String peer;
private int peerId;
public NoopExitSpan(int peerId)
{
this.peerId = peerId;
}
public NoopExitSpan(String peer)
{
this.peer = peer;
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Collections.Generic;
using System.Text;
using SkyWalking.NetworkProtocol.Trace;
namespace SkyWalking.Context.Trace
{
public class NoopSpan : ISpan
{
public int SpanId => 0;
public string OperationName { get => string.Empty; set { } }
public int OperationId { get => 0; set { } }
public ISpan ErrorOccurred()
{
return this;
}
public ISpan Log(Exception exception)
{
return this;
}
public ISpan Log(long timestamp, IDictionary<string, object> @event)
{
return this;
}
public void Ref(ITraceSegmentRef traceSegmentRef)
{
}
public ISpan SetComponent(IComponent component)
{
return this;
}
public ISpan SetComponent(string componentName)
{
return this;
}
public ISpan SetLayer(SpanLayer layer)
{
return this;
}
public ISpan Start()
{
return this;
}
public ISpan Start(long timestamp)
{
return this;
}
public ISpan Tag(string key, string value)
{
return this;
}
public virtual bool IsEntry => false;
public virtual bool IsExit => false;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.Linq;
using SkyWalking.Config;
using SkyWalking.Context.Ids;
using SkyWalking.Dictionarys;
using SkyWalking.NetworkProtocol;
namespace SkyWalking.Context.Trace
{
public class TraceSegmentRef : ITraceSegmentRef
{
private SegmentRefType _type;
private ID _traceSegmentId;
private int _spanId = -1;
private int _peerId = DictionaryUtil.NullValue;
private string _peerHost;
private int _entryApplicationInstanceId = DictionaryUtil.NullValue;
private int _parentApplicationInstanceId = DictionaryUtil.NullValue;
private string _entryOperationName;
private int _entryOperationId = DictionaryUtil.NullValue;
private string _parentOperationName;
private int _parentOperationId = DictionaryUtil.NullValue;
public TraceSegmentRef(IContextCarrier carrier)
{
_type = SegmentRefType.CrossProcess;
_traceSegmentId = carrier.TraceSegmentId;
_spanId = carrier.SpanId;
_parentApplicationInstanceId = carrier.ParentApplicationInstanceId;
_entryApplicationInstanceId = carrier.EntryApplicationInstanceId;
string host = carrier.PeerHost;
if (host.ToCharArray()[0] == '#')
{
_peerHost = host.Substring(1);
}
else
{
int.TryParse(host, out _peerId);
}
string entryOperationName = carrier.EntryOperationName;
if (entryOperationName.First() == '#')
{
_entryOperationName = entryOperationName.Substring(1);
}
else
{
int.TryParse(entryOperationName, out _entryOperationId);
}
string parentOperationName = carrier.EntryOperationName;
if (parentOperationName.First() == '#')
{
_parentOperationName = parentOperationName.Substring(1);
}
else
{
int.TryParse(parentOperationName, out _parentOperationId);
}
}
public TraceSegmentRef(IContextSnapshot contextSnapshot)
{
_type = SegmentRefType.CrossThread;
_traceSegmentId = contextSnapshot.TraceSegmentId;
_spanId = contextSnapshot.SpanId;
_parentApplicationInstanceId = RemoteDownstreamConfig.Agent.ApplicationInstanceId;
_entryApplicationInstanceId = contextSnapshot.EntryApplicationInstanceId;
string entryOperationName = contextSnapshot.EntryOperationName;
if (entryOperationName.First() == '#')
{
_entryOperationName = entryOperationName.Substring(1);
}
else
{
int.TryParse(entryOperationName, out _entryOperationId);
}
string parentOperationName = contextSnapshot.EntryOperationName;
if (parentOperationName.First() == '#')
{
_parentOperationName = parentOperationName.Substring(1);
}
else
{
int.TryParse(parentOperationName, out _parentOperationId);
}
}
public bool Equals(ITraceSegmentRef other)
{
if (other == null)
{
return false;
}
if (other == this)
{
return true;
}
if (!(other is TraceSegmentRef segmentRef))
{
return false;
}
if (_spanId != segmentRef._spanId)
{
return false;
}
return _traceSegmentId.Equals(segmentRef._traceSegmentId);
}
public override bool Equals(object obj)
{
var other = obj as ITraceSegmentRef;
return Equals(other);
}
public override int GetHashCode()
{
int result = _traceSegmentId.GetHashCode();
result = 31 * result + _spanId;
return result;
}
public string EntryOperationName => _entryOperationName;
public int EntryOperationId => _entryOperationId;
public int EntryApplicationInstance => _entryApplicationInstanceId;
public TraceSegmentReference Transform()
{
TraceSegmentReference traceSegmentReference = new TraceSegmentReference();
if (_type == SegmentRefType.CrossProcess)
{
traceSegmentReference.RefType = RefType.CrossProcess;
traceSegmentReference.ParentApplicationInstanceId = _parentApplicationInstanceId;
if (_peerId == DictionaryUtil.NullValue)
{
traceSegmentReference.NetworkAddress = _peerHost;
}
else
{
traceSegmentReference.NetworkAddressId = _peerId;
}
}
else
{
traceSegmentReference.RefType = RefType.CrossThread;
}
traceSegmentReference.EntryApplicationInstanceId = _entryApplicationInstanceId;
traceSegmentReference.ParentTraceSegmentId = _traceSegmentId.Transform();
traceSegmentReference.ParentSpanId = _spanId;
if (_entryOperationId == DictionaryUtil.NullValue)
{
traceSegmentReference.EntryServiceName = _entryOperationName;
}
else
{
traceSegmentReference.EntryServiceId = _entryOperationId;
}
if (_parentOperationId == DictionaryUtil.NullValue)
{
traceSegmentReference.ParentServiceName = _parentOperationName;
}
else
{
traceSegmentReference.ParentServiceId = _parentOperationId;
}
return traceSegmentReference;
}
}
}
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
namespace SkyWalking.Context
{
public class TraceContextCarrierItem : CarrierItem
{
private const string HEAD_NAME = "Trace-Context";
public TraceContextCarrierItem(String headValue, CarrierItem next)
: base(HEAD_NAME, headValue, next)
{
}
}
}
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" /> <Import Project="..\..\build\common.props" />
<PropertyGroup> <PropertyGroup>
<Description>SkyWalking core components.</Description> <Description>SkyWalking core components.</Description>
<AssemblyTitle>SkyWalking.Core</AssemblyTitle> <AssemblyTitle>SkyWalking.Core</AssemblyTitle>
...@@ -9,8 +7,11 @@ ...@@ -9,8 +7,11 @@
<AssemblyName>SkyWalking.Core</AssemblyName> <AssemblyName>SkyWalking.Core</AssemblyName>
<PackageId>SkyWalking.Core</PackageId> <PackageId>SkyWalking.Core</PackageId>
<PackageTags>SkyWalking;APM</PackageTags> <PackageTags>SkyWalking;APM</PackageTags>
<PackageReleaseNotes></PackageReleaseNotes> <PackageReleaseNotes>
</PackageReleaseNotes>
<RootNamespace>SkyWalking</RootNamespace> <RootNamespace>SkyWalking</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
</Project> <ProjectReference Include="..\SkyWalking.Abstractions\SkyWalking.Abstractions.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.Collections.Generic;
namespace SkyWalking.NetworkProtocol.Trace
{
public class ComponentsDefine
{
public static readonly OfficialComponent AspNetCore = new OfficialComponent(1, "AspNetCore");
private static readonly ComponentsDefine _instance = new ComponentsDefine();
public ComponentsDefine Instance
{
get
{
return _instance;
}
}
private Dictionary<int, string> _components;
private ComponentsDefine()
{
_components = new Dictionary<int, string>();
}
private void AddComponent(OfficialComponent component)
{
_components[component.Id] = component.Name;
}
public string GetComponentName(int componentId)
{
if (_components.TryGetValue(componentId, out var value))
{
return value;
}
return null;
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace SkyWalking.NetworkProtocol.Trace
{
/// <summary>
/// The <code>Component</code> represents component library , which has been supported by skywalking
/// </summary>
public interface IComponent
{
int Id { get; }
string Name { get; }
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace SkyWalking.NetworkProtocol.Trace
{
public class OfficialComponent : IComponent
{
public OfficialComponent(int id, string name)
{
Id = id;
Name = name;
}
public int Id { get; }
public string Name { get; }
}
}
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<Description>SkyWalking trace protocol.</Description>
<AssemblyTitle>SkyWalking.NetworkProtocol.Trace</AssemblyTitle>
<TargetFrameworks>netstandard1.6;net45</TargetFrameworks>
<AssemblyName>SkyWalking.NetworkProtocol.Trace</AssemblyName>
<PackageId>SkyWalking.NetworkProtocol.Trace</PackageId>
<PackageTags>SkyWalking</PackageTags>
<PackageReleaseNotes></PackageReleaseNotes>
</PropertyGroup>
</Project>
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