Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/twegner/spankindaddition #30

Closed
wants to merge 8 commits into from
6 changes: 3 additions & 3 deletions src/OpenTelemetry.Abstractions/Trace/ITracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface ITracer
/// <param name="spanName">Span name.</param>
/// <param name="spanKind">Span kind.</param>
/// <returns>Span builder for the span with the given name.</returns>
ISpanBuilder SpanBuilder(string spanName, SpanKind spanKind = SpanKind.Unspecified);
ISpanBuilder SpanBuilder(string spanName, SpanKind spanKind = SpanKind.Internal);

/// <summary>
/// Gets the span builder for the span with the given name and parent.
Expand All @@ -50,7 +50,7 @@ public interface ITracer
/// <param name="spanKind">Span kind.</param>
/// <param name="parent">Parent of the span.</param>
/// <returns>Span builder for the span with the given name and specified parent.</returns>
ISpanBuilder SpanBuilderWithExplicitParent(string spanName, SpanKind spanKind = SpanKind.Unspecified, ISpan parent = null);
ISpanBuilder SpanBuilderWithExplicitParent(string spanName, SpanKind spanKind = SpanKind.Internal, ISpan parent = null);

/// <summary>
/// Gets the span builder for the span with the give name and remote parent context.
Expand All @@ -59,6 +59,6 @@ public interface ITracer
/// <param name="spanKind">Span kind.</param>
/// <param name="remoteParentSpanContext">Remote parent context extracted from the wire.</param>
/// <returns>Span builder for the span with the given name and specified parent span context.</returns>
ISpanBuilder SpanBuilderWithRemoteParent(string spanName, SpanKind spanKind = SpanKind.Unspecified, ISpanContext remoteParentSpanContext = null);
ISpanBuilder SpanBuilderWithRemoteParent(string spanName, SpanKind spanKind = SpanKind.Internal, ISpanContext remoteParentSpanContext = null);
}
}
16 changes: 15 additions & 1 deletion src/OpenTelemetry.Abstractions/Trace/SpanKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum SpanKind
/// <summary>
/// Span kind was not specified.
/// </summary>
Unspecified = 0,
Internal = 0,

/// <summary>
/// Server span represents request incoming from external component.
Expand All @@ -35,5 +35,19 @@ public enum SpanKind
/// Client span represents outgoing request to the external component.
/// </summary>
Client = 2,

/// <summary>
/// Producer span represents output provided to external components. Unlike client and
/// server, there is no direct critical path latency relationship between producer and consumer
/// spans.
/// </summary>
Producer = 3,

/// <summary>
/// Consumer span represents output received from an external component. Unlike client and
/// server, there is no direct critical path latency relationship between producer and consumer
/// spans.
/// </summary>
Consumer = 4,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ await Task.Run(async () =>

// BUILDING resulting telemetry
OperationTelemetry result;
if (resultKind == SpanKind.Client)
if (resultKind == SpanKind.Client || resultKind == SpanKind.Producer)
{
var resultD = new DependencyTelemetry();
resultD.ResultCode = resultCode;
Expand Down Expand Up @@ -288,7 +288,7 @@ private void ExtractGenericProperties(ISpanData span, out SpanKind resultKind, o
resultKind = span.Kind;

// TODO: Should this be a part of generic logic?
if (resultKind == SpanKind.Unspecified)
if (resultKind == SpanKind.Internal)
{
if (span.HasRemoteParent.HasValue && span.HasRemoteParent.Value)
{
Expand Down Expand Up @@ -341,13 +341,23 @@ private void OverwriteSpanKindFromAttribute(IAttributeValue spanKindAttr, ref Sp
{
var kind = spanKindAttr.Match((s) => s, null, null, null, null);

if (kind == "server")
switch (kind.ToLower(CultureInfo.InvariantCulture))
{
resultKind = SpanKind.Server;
}
else
{
resultKind = SpanKind.Client;
case "server":
resultKind = SpanKind.Server;
break;
case "client":
resultKind = SpanKind.Client;
break;
case "producer":
resultKind = SpanKind.Producer;
trwegner marked this conversation as resolved.
Show resolved Hide resolved
break;
case "consumer":
resultKind = SpanKind.Consumer;
break;
default:
resultKind = SpanKind.Internal;
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ internal static Span ToProtoSpan(this ISpanData spanData)
return new Span
{
Name = new TruncatableString { Value = spanData.Name },
Kind = spanData.Kind == SpanKind.Client ? Span.Types.SpanKind.Client : Span.Types.SpanKind.Server,

// TODO: Utilize new Span.Types.SpanKind below when updated protos are incorporated
Kind = spanData.Kind == SpanKind.Client || spanData.Kind == SpanKind.Producer ? Span.Types.SpanKind.Client : Span.Types.SpanKind.Server,
TraceId = ByteString.CopyFrom(spanData.Context.TraceId.Bytes),
SpanId = ByteString.CopyFrom(spanData.Context.SpanId.Bytes),
ParentSpanId =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,43 @@ private string EncodeSpanId(ISpanId spanId)

private ZipkinSpanKind ToSpanKind(ISpanData spanData)
{
if (spanData.Kind == SpanKind.Server)
{
return ZipkinSpanKind.SERVER;
}
else if (spanData.Kind == SpanKind.Client)
var zipkinSpanKind = ZipkinSpanKind.CLIENT;

switch (spanData.Kind)
{
if (spanData.HasRemoteParent.HasValue && spanData.HasRemoteParent.Value)
{
return ZipkinSpanKind.SERVER;
}
case SpanKind.Server:
zipkinSpanKind = ZipkinSpanKind.SERVER;
break;
case SpanKind.Client:
if (spanData.HasRemoteParent.HasValue && spanData.HasRemoteParent.Value)
{
zipkinSpanKind = ZipkinSpanKind.SERVER;
}
else
{
zipkinSpanKind = ZipkinSpanKind.CLIENT;
}

break;
case SpanKind.Consumer:
zipkinSpanKind = ZipkinSpanKind.CONSUMER;
break;
case SpanKind.Producer:
if (spanData.HasRemoteParent.HasValue && spanData.HasRemoteParent.Value)
{
zipkinSpanKind = ZipkinSpanKind.CONSUMER;
}
else
{
zipkinSpanKind = ZipkinSpanKind.PRODUCER;
}

return ZipkinSpanKind.CLIENT;
break;
default:
break;
}

return ZipkinSpanKind.CLIENT;
return zipkinSpanKind;
}

private async Task SendSpansAsync(IEnumerable<ZipkinSpan> spans)
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry/Trace/NoopTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ internal NoopTracer()
{
}

public override ISpanBuilder SpanBuilderWithExplicitParent(string spanName, SpanKind spanKind = SpanKind.Unspecified, ISpan parent = null)
public override ISpanBuilder SpanBuilderWithExplicitParent(string spanName, SpanKind spanKind = SpanKind.Internal, ISpan parent = null)
{
return NoopSpanBuilder.CreateWithParent(spanName, spanKind, parent);
}

public override ISpanBuilder SpanBuilderWithRemoteParent(string spanName, SpanKind spanKind = SpanKind.Unspecified, ISpanContext remoteParentSpanContext = null)
public override ISpanBuilder SpanBuilderWithRemoteParent(string spanName, SpanKind spanKind = SpanKind.Internal, ISpanContext remoteParentSpanContext = null)
{
return NoopSpanBuilder.CreateWithRemoteParent(spanName, spanKind, remoteParentSpanContext);
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Trace/Span.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public override ISpanData ToSpanData()
linksSpanData,
null, // Not supported yet.
this.hasBeenEnded ? this.StatusWithDefault : null,
this.Kind.HasValue ? this.Kind.Value : SpanKind.Client,
this.Kind ?? SpanKind.Internal,
this.hasBeenEnded ? Timestamp.FromDateTimeOffset(this.endTime) : null);
}

Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry/Trace/Tracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public Tracer(IRandomGenerator randomGenerator, IStartEndHandler startEndHandler
this.spanBuilderOptions = new SpanBuilderOptions(randomGenerator, startEndHandler, traceConfig);
}

public override ISpanBuilder SpanBuilderWithExplicitParent(string spanName, SpanKind spanKind = SpanKind.Unspecified, ISpan parent = null)
public override ISpanBuilder SpanBuilderWithExplicitParent(string spanName, SpanKind spanKind = SpanKind.Internal, ISpan parent = null)
{
return Trace.SpanBuilder.CreateWithParent(spanName, spanKind, parent, this.spanBuilderOptions);
}

public override ISpanBuilder SpanBuilderWithRemoteParent(string spanName, SpanKind spanKind = SpanKind.Unspecified, ISpanContext remoteParentSpanContext = null)
public override ISpanBuilder SpanBuilderWithRemoteParent(string spanName, SpanKind spanKind = SpanKind.Internal, ISpanContext remoteParentSpanContext = null)
{
return Trace.SpanBuilder.CreateWithRemoteParent(spanName, spanKind, remoteParentSpanContext, this.spanBuilderOptions);
}
Expand Down
6 changes: 3 additions & 3 deletions src/OpenTelemetry/Trace/TracerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public IScope WithSpan(ISpan span)

// public final Runnable withSpan(Span span, Runnable runnable)
// public final <C> Callable<C> withSpan(Span span, final Callable<C> callable)
public ISpanBuilder SpanBuilder(string spanName, SpanKind spanKind = SpanKind.Unspecified)
public ISpanBuilder SpanBuilder(string spanName, SpanKind spanKind = SpanKind.Internal)
{
return this.SpanBuilderWithExplicitParent(spanName, spanKind, CurrentSpanUtils.CurrentSpan);
}

public abstract ISpanBuilder SpanBuilderWithExplicitParent(string spanName, SpanKind spanKind = SpanKind.Unspecified, ISpan parent = null);
public abstract ISpanBuilder SpanBuilderWithExplicitParent(string spanName, SpanKind spanKind = SpanKind.Internal, ISpan parent = null);

public abstract ISpanBuilder SpanBuilderWithRemoteParent(string spanName, SpanKind spanKind = SpanKind.Unspecified, ISpanContext remoteParentSpanContext = null);
public abstract ISpanBuilder SpanBuilderWithRemoteParent(string spanName, SpanKind spanKind = SpanKind.Internal, ISpanContext remoteParentSpanContext = null);
}
}
Loading