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

aligned ISpan operaitons with the spec #54

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions src/OpenTelemetry.Abstractions/Trace/ISpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,35 @@ namespace OpenTelemetry.Trace
/// </summary>
public interface ISpan
{
/// <summary>
/// Gets the span name. Use <code>UpdateSpan</code> to explicitly set the span name.
/// </summary>
string Name { get; }

/// <summary>
/// Gets the span context.
/// </summary>
ISpanContext Context { get; }

/// <summary>
/// Gets the span options.
/// Gets a value indicating whether this span will be recorded.
/// </summary>
SpanOptions Options { get; }
bool IsRecordingEvents { get; }

/// <summary>
/// Gets or sets the status of the span execution.
/// Sets the status of the span execution.
/// </summary>
Status Status { get; set; }

/// <summary>
/// Gets or sets the kind of a span.
/// </summary>
SpanKind? Kind { get; set; }
Status Status { set; }

/// <summary>
/// Gets a value indicating whether this span was already stopped.
/// </summary>
/// <remarks>This method is not compliant with the specification. https://github.com/open-telemetry/opentelemetry-specification/issues/55</remarks>
bool HasEnded { get; }

/// <summary>
/// Updates the <code>Span</code> name.
/// Updates the <see cref="Span"/> name.
///
/// If used, this will override the name provided via <code>SpanBuilder</code>.
/// Upon this update, any sampling behavior based on <code>Span</code> name will depend on the
/// If used, this will override the name provided via <see cref="ISpanBuilder"/>.
/// Upon this update, any sampling behavior based on <see cref="Span"/> name will depend on the
/// implementation.
/// </summary>
/// <param name="name">name of the span.</param>
/// <param name="name">Name of the span.</param>
void UpdateName(string name);

/// <summary>
Expand All @@ -75,10 +66,32 @@ public interface ISpan
void SetAttribute(string key, IAttributeValue value);

/// <summary>
/// Puts a list of attributes to the span.
/// Puts a new attribute to the span.
/// </summary>
/// <param name="key">Key of the attribute.</param>
/// <param name="value">Attribute value.</param>
void SetAttribute(string key, string value);

/// <summary>
/// Puts a new attribute to the span.
/// </summary>
/// <param name="attributes">Collection of attributes name/value pairs.</param>
void SetAttributes(IDictionary<string, IAttributeValue> attributes);
/// <param name="key">Key of the attribute.</param>
/// <param name="value">Attribute value.</param>
void SetAttribute(string key, long value);

/// <summary>
/// Puts a new attribute to the span.
/// </summary>
/// <param name="key">Key of the attribute.</param>
/// <param name="value">Attribute value.</param>
void SetAttribute(string key, double value);

/// <summary>
/// Puts a new attribute to the span.
/// </summary>
/// <param name="key">Key of the attribute.</param>
/// <param name="value">Attribute value.</param>
void SetAttribute(string key, bool value);

/// <summary>
/// Adds a single <see cref="IEvent"/> to the <see cref="ISpan"/>.
Expand Down
26 changes: 14 additions & 12 deletions src/OpenTelemetry.Abstractions/Trace/SpanExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,52 +171,54 @@ public static ISpan PutHttpStatusCode(this ISpan span, int statusCode, string re
{
span.PutHttpStatusCodeAttribute(statusCode);

Status newStatus = Status.Ok;

if ((int)statusCode < 200)
{
span.Status = Status.Unknown;
newStatus = Status.Unknown;
}
else if ((int)statusCode >= 200 && (int)statusCode <= 399)
{
span.Status = Status.Ok;
newStatus = Status.Ok;
}
else if ((int)statusCode == 400)
{
span.Status = Status.InvalidArgument;
newStatus = Status.InvalidArgument;
}
else if ((int)statusCode == 401)
{
span.Status = Status.Unauthenticated;
newStatus = Status.Unauthenticated;
}
else if ((int)statusCode == 403)
{
span.Status = Status.PermissionDenied;
newStatus = Status.PermissionDenied;
}
else if ((int)statusCode == 404)
{
span.Status = Status.NotFound;
newStatus = Status.NotFound;
}
else if ((int)statusCode == 429)
{
span.Status = Status.ResourceExhausted;
newStatus = Status.ResourceExhausted;
}
else if ((int)statusCode == 501)
{
span.Status = Status.Unimplemented;
newStatus = Status.Unimplemented;
}
else if ((int)statusCode == 503)
{
span.Status = Status.Unavailable;
newStatus = Status.Unavailable;
}
else if ((int)statusCode == 504)
{
span.Status = Status.DeadlineExceeded;
newStatus = Status.DeadlineExceeded;
}
else
{
span.Status = Status.Unknown;
newStatus = Status.Unknown;
}

span.Status = span.Status.WithDescription(reasonPhrase);
span.Status = newStatus.WithDescription(reasonPhrase);

return span;
}
Expand Down
24 changes: 18 additions & 6 deletions src/OpenTelemetry/Trace/Internal/BlankSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ private BlankSpan()

public override Status Status { get; set; }

public override SpanKind? Kind { get; set; }

public override DateTimeOffset EndTime
{
get
Expand Down Expand Up @@ -69,9 +67,7 @@ public override ISpanId ParentSpanId

public override bool HasEnded => true;

public override void SetAttributes(IDictionary<string, IAttributeValue> attributes)
{
}
public override bool IsRecordingEvents => false;

public override void SetAttribute(string key, IAttributeValue value)
{
Expand Down Expand Up @@ -100,7 +96,23 @@ public override string ToString()

public override ISpanData ToSpanData()
{
throw new NotImplementedException();
return null;
}

public override void SetAttribute(string key, string value)
{
}

public override void SetAttribute(string key, long value)
{
}

public override void SetAttribute(string key, double value)
{
}

public override void SetAttribute(string key, bool value)
{
}
}
}
4 changes: 2 additions & 2 deletions src/OpenTelemetry/Trace/Internal/StartEndHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public StartEndHandler(ISpanExporter spanExporter, IRunningSpanStore runningSpan

public void OnEnd(ISpan span)
{
if ((span.Options.HasFlag(SpanOptions.RecordEvents) && this.enqueueEventForNonSampledSpans)
if ((span.IsRecordingEvents && this.enqueueEventForNonSampledSpans)
|| span.Context.TraceOptions.IsSampled)
{
this.eventQueue.Enqueue(new SpanEndEvent(span, this.spanExporter, this.runningSpanStore, this.sampledSpanStore));
Expand All @@ -50,7 +50,7 @@ public void OnEnd(ISpan span)

public void OnStart(ISpan span)
{
if (span.Options.HasFlag(SpanOptions.RecordEvents) && this.enqueueEventForNonSampledSpans)
if (span.IsRecordingEvents && this.enqueueEventForNonSampledSpans)
{
this.eventQueue.Enqueue(new SpanStartEvent(span, this.runningSpanStore));
}
Expand Down
Loading