Skip to content

Commit

Permalink
Add support for ms, mr and ma
Browse files Browse the repository at this point in the history
Fixes #150
  • Loading branch information
Pierre-Hugues Jeanneret committed Oct 9, 2017
1 parent 46a4e02 commit cafc2ea
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Src/zipkin4net/Src/Annotation/IAnnotationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public interface IAnnotationVisitor
void Visit(ServerSend serverSend);
void Visit(WireSend wireSend);
void Visit(WireRecv wireRecv);
void Visit(MessageSendStart messageSendStart);
void Visit(MessageSendStop messageSendStop);
void Visit(MessageRecvStart messageRecvStart);
void Visit(MessageRecvStop messageRecvStop);
void Visit(MessageAddr messageAddr);
void Visit(Rpc rpc);
void Visit(ServiceName serviceName);
void Visit(LocalAddr localAddr);
Expand Down
46 changes: 46 additions & 0 deletions Src/zipkin4net/Src/Annotation/MessageAddr.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Net;

namespace zipkin4net.Annotation
{
public sealed class MessageAddr : IAnnotation
{
public string ServiceName { get; }
public IPEndPoint Endpoint { get; }

internal MessageAddr(string serviceName, IPEndPoint endpoint)
{
ServiceName = serviceName;
Endpoint = endpoint;
}

public override string ToString()
{
return string.Format("{0}: {1}/{2}", GetType().Name, ServiceName, Endpoint);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
var messageAddr = (MessageAddr)obj;
return Endpoint.Equals(messageAddr.Endpoint)
&& string.Equals(ServiceName, messageAddr.ServiceName, StringComparison.OrdinalIgnoreCase);
}

public override int GetHashCode()
{
var hashCode = -2129424941;
hashCode = hashCode * -1521134295 + ServiceName.GetHashCode();
hashCode = hashCode * -1521134295 + Endpoint.GetHashCode();
return hashCode;
}

public void Accept(IAnnotationVisitor visitor)
{
visitor.Visit(this);
}
}
}
18 changes: 18 additions & 0 deletions Src/zipkin4net/Src/Annotation/MessageRecvStart.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace zipkin4net.Annotation
{
public sealed class MessageRecvStart : IAnnotation
{
internal MessageRecvStart()
{}

public override string ToString()
{
return GetType().Name;
}

public void Accept(IAnnotationVisitor visitor)
{
visitor.Visit(this);
}
}
}
18 changes: 18 additions & 0 deletions Src/zipkin4net/Src/Annotation/MessageRecvStop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace zipkin4net.Annotation
{
public sealed class MessageRecvStop : IAnnotation
{
internal MessageRecvStop()
{}

public override string ToString()
{
return GetType().Name;
}

public void Accept(IAnnotationVisitor visitor)
{
visitor.Visit(this);
}
}
}
18 changes: 18 additions & 0 deletions Src/zipkin4net/Src/Annotation/MessageSendStart.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace zipkin4net.Annotation
{
public sealed class MessageSendStart : IAnnotation
{
internal MessageSendStart()
{}

public override string ToString()
{
return GetType().Name;
}

public void Accept(IAnnotationVisitor visitor)
{
visitor.Visit(this);
}
}
}
18 changes: 18 additions & 0 deletions Src/zipkin4net/Src/Annotation/MessageSendStop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace zipkin4net.Annotation
{
public sealed class MessageSendStop : IAnnotation
{
internal MessageSendStop()
{}

public override string ToString()
{
return GetType().Name;
}

public void Accept(IAnnotationVisitor visitor)
{
visitor.Visit(this);
}
}
}
29 changes: 29 additions & 0 deletions Src/zipkin4net/Src/Annotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public static class Annotations
private static readonly IAnnotation AnnServerSend = new ServerSend();
private static readonly IAnnotation AnnWireSend = new WireSend();
private static readonly IAnnotation AnnWireRecv = new WireRecv();
private static readonly IAnnotation AnnMessageSendStart = new MessageSendStart();
private static readonly IAnnotation AnnMessageSendStop = new MessageSendStop();
private static readonly IAnnotation AnnMessageRecvStart = new MessageRecvStart();
private static readonly IAnnotation AnnMessageRecvStop = new MessageRecvStop();
private static readonly IAnnotation AnnLocalOperationStop = new LocalOperationStop();

public static IAnnotation ClientRecv()
Expand Down Expand Up @@ -47,6 +51,31 @@ public static IAnnotation WireRecv()
return AnnWireRecv;
}

public static IAnnotation MessageSendStart()
{
return AnnMessageSendStart;
}

public static IAnnotation MessageSendStop()
{
return AnnMessageSendStop;
}

public static IAnnotation MessageRecvStart()
{
return AnnMessageRecvStart;
}

public static IAnnotation MessageRecvStop()
{
return AnnMessageRecvStop;
}

public static IAnnotation MessageAddr(string serviceName, IPEndPoint endPoint)
{
return new MessageAddr(serviceName, endPoint);
}

public static IAnnotation LocalOperationStart(string name)
{
return new LocalOperationStart(name);
Expand Down
25 changes: 25 additions & 0 deletions Src/zipkin4net/Src/Tracers/Zipkin/ZipkinAnnotationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ public void Visit(WireRecv wireRecv)
AddTimestampedAnnotation(zipkinCoreConstants.WIRE_RECV);
}

public void Visit(MessageSendStart messageSendStart)
{
AddTimestampedAnnotation(zipkinCoreConstants.MESSAGE_SEND);
}

public void Visit(MessageSendStop messageSendStop)
{
_span.SetAsComplete(_record.Timestamp);
}

public void Visit(MessageRecvStart messageRecvStart)
{
AddTimestampedAnnotation(zipkinCoreConstants.MESSAGE_RECV);
}

public void Visit(MessageRecvStop messageRecvStop)
{
_span.SetAsComplete(_record.Timestamp);
}

public void Visit(MessageAddr messageAddr)
{
AddBinaryAnnotation(zipkinCoreConstants.MESSAGE_ADDR, true, messageAddr.ServiceName, messageAddr.Endpoint);
}

public void Visit(Event ev)
{
AddTimestampedAnnotation(ev.EventName);
Expand Down
9 changes: 7 additions & 2 deletions Src/zipkin4net/Src/zipkin4net.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -53,6 +53,11 @@
<Compile Include="Annotations.cs" />
<Compile Include="Annotation\Addr.cs" />
<Compile Include="Annotation\ClientAddr.cs" />
<Compile Include="Annotation\MessageAddr.cs" />
<Compile Include="Annotation\MessageRecvStart.cs" />
<Compile Include="Annotation\MessageRecvStop.cs" />
<Compile Include="Annotation\MessageSendStart.cs" />
<Compile Include="Annotation\MessageSendStop.cs" />
<Compile Include="Annotation\ServerAddr.cs" />
<Compile Include="Annotation\LocalOperationStart.cs" />
<Compile Include="Annotation\LocalOperationStop.cs" />
Expand Down Expand Up @@ -136,4 +141,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
5 changes: 5 additions & 0 deletions Src/zipkin4net/Tests/T_Annotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public void FactoryReturnsCorrectTypes()
Assert.IsInstanceOf<Event>(Annotations.Event(""));
Assert.IsInstanceOf<ClientAddr>(Annotations.ClientAddr(null));
Assert.IsInstanceOf<ServerAddr>(Annotations.ServerAddr(null, null));
Assert.IsInstanceOf<MessageAddr>(Annotations.MessageAddr(null, null));
Assert.IsInstanceOf<MessageRecvStart>(Annotations.MessageRecvStart());
Assert.IsInstanceOf<MessageRecvStop>(Annotations.MessageRecvStop());
Assert.IsInstanceOf<MessageSendStart>(Annotations.MessageSendStart());
Assert.IsInstanceOf<MessageSendStop>(Annotations.MessageSendStop());
}

}
Expand Down
6 changes: 6 additions & 0 deletions Src/zipkin4net/Tests/Tracers/Zipkin/T_Span.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public void DurationAndSpanStartedSetWhenSetAsComplete()
VerifySpanDurationComputedWhenSetAsComplete(Annotations.ServerRecv(), Annotations.ServerSend(), isRootSpan: true, isSpanStartedAndDurationSet: true);
VerifySpanDurationComputedWhenSetAsComplete(Annotations.ServerRecv(), Annotations.ServerSend(), isRootSpan: false, isSpanStartedAndDurationSet: false);
VerifySpanDurationComputedWhenSetAsComplete(Annotations.LocalOperationStart("Operation"), Annotations.LocalOperationStop(), isRootSpan: false, isSpanStartedAndDurationSet: true);
VerifySpanDurationComputedWhenSetAsComplete(Annotations.MessageSendStart(), Annotations.MessageSendStop(), isRootSpan: false, isSpanStartedAndDurationSet: false);
VerifySpanDurationComputedWhenSetAsComplete(Annotations.MessageRecvStart(), Annotations.MessageRecvStop(), isRootSpan: false, isSpanStartedAndDurationSet: false);
}

private static void VerifySpanDurationComputedWhenSetAsComplete(IAnnotation start, IAnnotation stop, bool isRootSpan, bool isSpanStartedAndDurationSet)
Expand Down Expand Up @@ -107,6 +109,10 @@ public void SpanDoesntHaveDurationIfIncomplete()
Assert.False(GetSpanDuration(offset, Annotations.ClientSend()).HasValue);
Assert.False(GetSpanDuration(offset, Annotations.LocalOperationStart("Operation")).HasValue);
Assert.False(GetSpanDuration(offset, Annotations.LocalOperationStop()).HasValue);
Assert.False(GetSpanDuration(offset, Annotations.MessageRecvStart()).HasValue);
Assert.False(GetSpanDuration(offset, Annotations.MessageRecvStop()).HasValue);
Assert.False(GetSpanDuration(offset, Annotations.MessageSendStart()).HasValue);
Assert.False(GetSpanDuration(offset, Annotations.MessageSendStop()).HasValue);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public void SimpleAnnotationsCorrectlyAdded()
AnnotationCorrectlyAdded(Annotations.WireRecv(), zipkinCoreConstants.WIRE_RECV, false, false);
AnnotationCorrectlyAdded(Annotations.WireSend(), zipkinCoreConstants.WIRE_SEND, false, false);
AnnotationCorrectlyAdded(Annotations.LocalOperationStart("Operation"), zipkinCoreConstants.LOCAL_COMPONENT, true, false);
AnnotationCorrectlyAdded(Annotations.MessageRecvStart(), zipkinCoreConstants.MESSAGE_RECV, false, false);
AnnotationCorrectlyAdded(Annotations.MessageSendStart(), zipkinCoreConstants.MESSAGE_SEND, false, false);
AnnotationCorrectlyAdded(Annotations.MessageAddr("service", new IPEndPoint(0, 1)), zipkinCoreConstants.MESSAGE_ADDR, true, false);
}

private static void AnnotationCorrectlyAdded(IAnnotation ann, string expectedValue, bool isBinaryAnnotation, bool spanCompleted)
Expand Down

0 comments on commit cafc2ea

Please sign in to comment.