Skip to content

Commit

Permalink
remove options from end and make SpanContext specific class (open-tel…
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKanzhelev authored Jun 3, 2019
1 parent 98a82fa commit bca11b8
Show file tree
Hide file tree
Showing 51 changed files with 105 additions and 206 deletions.
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Abstractions/Trace/ISampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public interface ISampler
/// </param>
/// <param name="parentLinks">Links associated with the parent span.</param>
/// <returns>True of span needs to be created. False otherwise.</returns>
bool ShouldSample(ISpanContext parentContext, ITraceId traceId, ISpanId spanId, string name, IEnumerable<ISpan> parentLinks);
bool ShouldSample(SpanContext parentContext, ITraceId traceId, ISpanId spanId, string name, IEnumerable<ISpan> parentLinks);
}
}
8 changes: 1 addition & 7 deletions src/OpenTelemetry.Abstractions/Trace/ISpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface ISpan
/// <summary>
/// Gets the span context.
/// </summary>
ISpanContext Context { get; }
SpanContext Context { get; }

/// <summary>
/// Gets a value indicating whether this span will be recorded.
Expand Down Expand Up @@ -118,12 +118,6 @@ public interface ISpan
/// <param name="link">Link to add to the span.</param>
void AddLink(ILink link);

/// <summary>
/// Complete the span and set end span options.
/// </summary>
/// <param name="options">Span completion options.</param>
void End(EndSpanOptions options);

/// <summary>
/// End the span.
/// </summary>
Expand Down
49 changes: 0 additions & 49 deletions src/OpenTelemetry.Abstractions/Trace/ISpanContext.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/OpenTelemetry.Abstractions/Trace/ISpanData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace OpenTelemetry.Trace
public interface ISpanData
{
/// <summary>
/// Gets the <see cref="ISpanContext"/>.
/// Gets the <see cref="SpanContext"/>.
/// </summary>
ISpanContext Context { get; }
SpanContext Context { get; }

/// <summary>
/// Gets the parent <see cref="ISpanId"/>.
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Abstractions/Trace/ITracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public interface ITracer
/// <param name="kind">Span kind.</param>
/// <param name="parentContext">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 SpanBuilderWithParentContext(string name, SpanKind kind = SpanKind.Internal, ISpanContext parentContext = null);
ISpanBuilder SpanBuilderWithParentContext(string name, SpanKind kind = SpanKind.Internal, SpanContext parentContext = null);

/// <summary>
/// Records <see cref="ISpanData"/>. This API allows to send a pre-populated span object to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public interface IBinaryFormat
/// </summary>
/// <param name="bytes">Bytes array with the envoded span context in it.</param>
/// <returns>Span context deserialized from the byte array.</returns>
ISpanContext FromByteArray(byte[] bytes);
SpanContext FromByteArray(byte[] bytes);

/// <summary>
/// Serialize span context into the bytes array.
/// </summary>
/// <param name="spanContext">Span context to serialize.</param>
/// <returns>Byte array with the encoded span context in it.</returns>
byte[] ToByteArray(ISpanContext spanContext);
byte[] ToByteArray(SpanContext spanContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface ITextFormat
/// <param name="spanContext">Span context to transmit over the wire.</param>
/// <param name="carrier">Object to set context on. Instance of this object will be passed to setter.</param>
/// <param name="setter">Action that will set name and value pair on the object.</param>
void Inject<T>(ISpanContext spanContext, T carrier, Action<T, string, string> setter);
void Inject<T>(SpanContext spanContext, T carrier, Action<T, string, string> setter);

/// <summary>
/// Extracts span context from textual representation.
Expand All @@ -48,6 +48,6 @@ public interface ITextFormat
/// <param name="carrier">Object to extract context from. Instance of this object will be passed to the getter.</param>
/// <param name="getter">Function that will return string value of a key with the specified name.</param>
/// <returns>Span context from it's text representation.</returns>
ISpanContext Extract<T>(T carrier, Func<T, string, IEnumerable<string>> getter);
SpanContext Extract<T>(T carrier, Func<T, string, IEnumerable<string>> getter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public string Description
}
}

public bool ShouldSample(ISpanContext parentContext, ITraceId traceId, ISpanId spanId, string name, IEnumerable<ISpan> parentLinks)
public bool ShouldSample(SpanContext parentContext, ITraceId traceId, ISpanId spanId, string name, IEnumerable<ISpan> parentLinks)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public string Description
}
}

public bool ShouldSample(ISpanContext parentContext, ITraceId traceId, ISpanId spanId, string name, IEnumerable<ISpan> parentLinks)
public bool ShouldSample(SpanContext parentContext, ITraceId traceId, ISpanId spanId, string name, IEnumerable<ISpan> parentLinks)
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public string Description

public long IdUpperBound { get; }

public bool ShouldSample(ISpanContext parentContext, ITraceId traceId, ISpanId spanId, string name, IEnumerable<ISpan> parentLinks)
public bool ShouldSample(SpanContext parentContext, ITraceId traceId, ISpanId spanId, string name, IEnumerable<ISpan> parentLinks)
{
// If the parent is sampled keep the sampling decision.
if (parentContext != null && parentContext.TraceOptions.IsSampled)
Expand Down
28 changes: 14 additions & 14 deletions src/OpenTelemetry.Abstractions/Trace/SpanContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ namespace OpenTelemetry.Trace
/// child <see cref="ISpan"/> and across process boundaries. It contains the identifiers <see cref="TraceId"/>
/// and <see cref="SpanId"/> associated with the <see cref="ISpan"/> and a set of <see cref="TraceOptions"/>.
/// </summary>
public sealed class SpanContext : ISpanContext
public sealed class SpanContext
{
/// <summary>
/// A blank <see cref="ISpanContext"/> that can be used for no-op operations.
/// A blank <see cref="SpanContext"/> that can be used for no-op operations.
/// </summary>
public static readonly SpanContext Blank = new SpanContext(Trace.TraceId.Invalid, Trace.SpanId.Invalid, TraceOptions.Default, Tracestate.Empty);

Expand All @@ -37,39 +37,39 @@ private SpanContext(ITraceId traceId, ISpanId spanId, TraceOptions traceOptions,
}

/// <summary>
/// Gets the <see cref="ITraceId"/> associated with this <see cref="ISpanContext"/>.
/// Gets the <see cref="ITraceId"/> associated with this <see cref="SpanContext"/>.
/// </summary>
public ITraceId TraceId { get; }

/// <summary>
/// Gets the <see cref="ISpanId"/> associated with this <see cref="ISpanContext"/>.
/// Gets the <see cref="ISpanId"/> associated with this <see cref="SpanContext"/>.
/// </summary>
public ISpanId SpanId { get; }

/// <summary>
/// Gets the <see cref="TraceOptions"/> associated with this <see cref="ISpanContext"/>.
/// Gets the <see cref="TraceOptions"/> associated with this <see cref="SpanContext"/>.
/// </summary>
public TraceOptions TraceOptions { get; }

/// <summary>
/// Gets a value indicating whether this <see cref="ISpanContext"/> is valid.
/// Gets a value indicating whether this <see cref="SpanContext"/> is valid.
/// </summary>
public bool IsValid => this.TraceId.IsValid && this.SpanId.IsValid;

/// <summary>
/// Gets the <see cref="Tracestate"/> associated with this <see cref="ISpanContext"/>.
/// Gets the <see cref="Tracestate"/> associated with this <see cref="SpanContext"/>.
/// </summary>
public Tracestate Tracestate { get; }

/// <summary>
/// Creates a new <see cref="ISpanContext"/> with the given identifiers and options.
/// Creates a new <see cref="SpanContext"/> with the given identifiers and options.
/// </summary>
/// <param name="traceId">The <see cref="ITraceId"/> to associate with the <see cref="ISpanContext"/>.</param>
/// <param name="spanId">The <see cref="ISpanId"/> to associate with the <see cref="ISpanContext"/>.</param>
/// <param name="traceOptions">The <see cref="TraceOptions"/> to associate with the <see cref="ISpanContext"/>.</param>
/// <param name="tracestate">The <see cref="Tracestate"/> to associate with the <see cref="ISpanContext"/>.</param>
/// <returns>A new <see cref="ISpanContext"/> with the given identifiers and options.</returns>
public static ISpanContext Create(ITraceId traceId, ISpanId spanId, TraceOptions traceOptions, Tracestate tracestate)
/// <param name="traceId">The <see cref="ITraceId"/> to associate with the <see cref="SpanContext"/>.</param>
/// <param name="spanId">The <see cref="ISpanId"/> to associate with the <see cref="SpanContext"/>.</param>
/// <param name="traceOptions">The <see cref="TraceOptions"/> to associate with the <see cref="SpanContext"/>.</param>
/// <param name="tracestate">The <see cref="Tracestate"/> to associate with the <see cref="SpanContext"/>.</param>
/// <returns>A new <see cref="SpanContext"/> with the given identifiers and options.</returns>
public static SpanContext Create(ITraceId traceId, ISpanId spanId, TraceOptions traceOptions, Tracestate tracestate)
{
return new SpanContext(traceId, spanId, traceOptions, tracestate);
}
Expand Down
6 changes: 3 additions & 3 deletions src/OpenTelemetry.Abstractions/Trace/SpanData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace OpenTelemetry.Trace
public sealed class SpanData : ISpanData
{
internal SpanData(
ISpanContext context,
SpanContext context,
ISpanId parentSpanId,
string name,
Timestamp startTimestamp,
Expand All @@ -52,7 +52,7 @@ internal SpanData(
}

/// <inheritdoc/>
public ISpanContext Context { get; }
public SpanContext Context { get; }

/// <inheritdoc/>
public ISpanId ParentSpanId { get; }
Expand Down Expand Up @@ -100,7 +100,7 @@ internal SpanData(
/// <param name="endTimestamp">The end <see cref="Timestamp"/> of the <see cref="ISpan"/>.</param>
/// <returns>A new immutable <see cref="SpanData"/>.</returns>
public static ISpanData Create(
ISpanContext context,
SpanContext context,
ISpanId parentSpanId,
string name,
Timestamp startTimestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void DrainSession(ISpan parentSpan, IEnumerable<IProfiledCommand>
}
}

internal static bool ShouldSample(ISpanContext parentContext, string name, ISampler sampler, out ISpanContext context, out ISpanId parentSpanId)
internal static bool ShouldSample(SpanContext parentContext, string name, ISampler sampler, out SpanContext context, out ISpanId parentSpanId)
{
var traceId = TraceId.Invalid;
var tracestate = Tracestate.Empty;
Expand Down Expand Up @@ -80,7 +80,7 @@ internal static bool ShouldSample(ISpanContext parentContext, string name, ISamp
return result;
}

internal static ISpanData ProfiledCommandToSpanData(ISpanContext context, string name, ISpanId parentSpanId, IProfiledCommand command)
internal static ISpanData ProfiledCommandToSpanData(SpanContext context, string name, ISpanId parentSpanId, IProfiledCommand command)
{
// use https://github.com/opentracing/specification/blob/master/semantic_conventions.md for now

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task ExportAsync(IEnumerable<ISpanData> spanDataList)

internal ZipkinSpan GenerateSpan(ISpanData spanData, ZipkinEndpoint localEndpoint)
{
ISpanContext context = spanData.Context;
SpanContext context = spanData.Context;
long startTimestamp = this.ToEpochMicroseconds(spanData.StartTimestamp);
long endTimestamp = this.ToEpochMicroseconds(spanData.EndTimestamp);

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/OpenTelemetry/Trace/Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ private Link(ITraceId traceId, ISpanId spanId, LinkType type, IDictionary<string

public IDictionary<string, IAttributeValue> Attributes { get; }

public static ILink FromSpanContext(ISpanContext context, LinkType type)
public static ILink FromSpanContext(SpanContext context, LinkType type)
{
return new Link(context.TraceId, context.SpanId, type, EmptyAttributes);
}

public static ILink FromSpanContext(ISpanContext context, LinkType type, IDictionary<string, IAttributeValue> attributes)
public static ILink FromSpanContext(SpanContext context, LinkType type, IDictionary<string, IAttributeValue> attributes)
{
IDictionary<string, IAttributeValue> copy = new Dictionary<string, IAttributeValue>(attributes);
return new Link(
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Trace/NoopSpanBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal static ISpanBuilder SetParent(string name, SpanKind kind, ISpan parent
return new NoopSpanBuilder(name, kind);
}

internal static ISpanBuilder SetParent(string name, SpanKind kind, ISpanContext parentContext = null)
internal static ISpanBuilder SetParent(string name, SpanKind kind, SpanContext parentContext = null)
{
return new NoopSpanBuilder(name, kind);
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Trace/NoopTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override ISpanBuilder SpanBuilderWithParent(string name, SpanKind kind =
}

/// <inheritdoc/>
public override ISpanBuilder SpanBuilderWithParentContext(string name, SpanKind kind = SpanKind.Internal, ISpanContext parentContext = null)
public override ISpanBuilder SpanBuilderWithParentContext(string name, SpanKind kind = SpanKind.Internal, SpanContext parentContext = null)
{
return NoopSpanBuilder.SetParent(name, kind, parentContext);
}
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry/Trace/Propagation/B3Format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override ISet<string> Fields
}

/// <inheritdoc/>
public override ISpanContext Extract<T>(T carrier, Func<T, string, IEnumerable<string>> getter)
public override SpanContext Extract<T>(T carrier, Func<T, string, IEnumerable<string>> getter)
{
if (carrier == null)
{
Expand Down Expand Up @@ -111,7 +111,7 @@ public override ISpanContext Extract<T>(T carrier, Func<T, string, IEnumerable<s
}

/// <inheritdoc/>
public override void Inject<T>(ISpanContext spanContext, T carrier, Action<T, string, string> setter)
public override void Inject<T>(SpanContext spanContext, T carrier, Action<T, string, string> setter)
{
if (spanContext == null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry/Trace/Propagation/BinaryFormatBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ internal static IBinaryFormat NoopBinaryFormat
}
}

public abstract ISpanContext FromByteArray(byte[] bytes);
public abstract SpanContext FromByteArray(byte[] bytes);

public abstract byte[] ToByteArray(ISpanContext spanContext);
public abstract byte[] ToByteArray(SpanContext spanContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class BinaryFormat : BinaryFormatBase
private const int TraceOptionOffset = TraceOptionFieldIdOffset + IdSize;
private const int FormatLength = (4 * IdSize) + TraceId.Size + SpanId.Size + TraceOptions.Size;

public override ISpanContext FromByteArray(byte[] bytes)
public override SpanContext FromByteArray(byte[] bytes)
{
if (bytes == null)
{
Expand Down Expand Up @@ -80,7 +80,7 @@ public override ISpanContext FromByteArray(byte[] bytes)
}
}

public override byte[] ToByteArray(ISpanContext spanContext)
public override byte[] ToByteArray(SpanContext spanContext)
{
if (spanContext == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace OpenTelemetry.Trace.Propagation.Implementation

internal class NoopBinaryFormat : IBinaryFormat
{
public ISpanContext FromByteArray(byte[] bytes)
public SpanContext FromByteArray(byte[] bytes)
{
if (bytes == null)
{
Expand All @@ -30,7 +30,7 @@ public ISpanContext FromByteArray(byte[] bytes)
return SpanContext.Blank;
}

public byte[] ToByteArray(ISpanContext spanContext)
public byte[] ToByteArray(SpanContext spanContext)
{
if (spanContext == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal NoopTextFormat()

public override ISet<string> Fields => new HashSet<string>();

public override void Inject<T>(ISpanContext spanContext, T carrier, Action<T, string, string> setter)
public override void Inject<T>(SpanContext spanContext, T carrier, Action<T, string, string> setter)
{
if (spanContext == null)
{
Expand All @@ -45,7 +45,7 @@ public override void Inject<T>(ISpanContext spanContext, T carrier, Action<T, st
}
}

public override ISpanContext Extract<T>(T carrier, Func<T, string, IEnumerable<string>> getter)
public override SpanContext Extract<T>(T carrier, Func<T, string, IEnumerable<string>> getter)
{
if (carrier == null)
{
Expand Down
Loading

0 comments on commit bca11b8

Please sign in to comment.