Skip to content

Commit

Permalink
Updates to make the SpanLink API more similar to the Activity API:
Browse files Browse the repository at this point in the history
- Rename the method from AddSpanLink to AddLink (this also mirrors the suggestion from OpenTelemetry Tracing API spec)
- Return the Span object instead of returning nothing
  • Loading branch information
zacharycmontoya committed Nov 22, 2024
1 parent 6c3d293 commit 2bfad3d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tracer/src/Datadog.Trace/Activity/OtlpHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private static void ExtractActivityLinks<TInner>(Span span, IActivity5? activity
spanContext.PropagatedTags = traceTags;

var spanLink = new SpanLink(spanContext);
span.AddSpanLink(spanLink);
span.AddLink(spanLink);

if (duckLink.Tags is not null)
{
Expand Down
7 changes: 4 additions & 3 deletions tracer/src/Datadog.Trace/Span.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,16 +539,17 @@ private void WriteCloseDebugMessage()
/// Adds a SpanLink to the current Span if the Span is active.
/// </summary>
/// <param name="spanLink">The SpanLink to add</param>
internal void AddSpanLink(SpanLink spanLink)
internal Span AddLink(SpanLink spanLink)
{
if (IsFinished)
{
Log.Warning("AddSpanLink should not be called after the span was closed");
return;
Log.Warning("AddLink should not be called after the span was closed");
return this;
}

SpanLinks ??= new List<SpanLink>();
SpanLinks.Add(spanLink);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ public void SpanLink_Tag_Serialization()
new("pair", "false"),
new("arbitrary", "56709")
};
spans[0].AddSpanLink(new SpanLink(spans[1].Context, attributesToAdd));
spans[0].AddLink(new SpanLink(spans[1].Context, attributesToAdd));

var tmpSpanLink = new SpanLink(spans[2].Context);
spans[1].AddSpanLink(tmpSpanLink);
spans[1].AddLink(tmpSpanLink);
tmpSpanLink.AddAttribute("attribute1", "value1");
tmpSpanLink.AddAttribute("attribute2", "value2");

spans[1].AddSpanLink(new SpanLink(spans[0].Context));
spans[1].AddLink(new SpanLink(spans[0].Context));

foreach (var span in spans)
{
Expand Down
4 changes: 2 additions & 2 deletions tracer/test/Datadog.Trace.Tests/SpanLinksTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void AddLink_AfterSpanFinished_IsNoOp()

childSpan.Finish();

childSpan.AddSpanLink(spanLink);
childSpan.AddLink(spanLink);
childSpan.SpanLinks.Should().BeNullOrEmpty();
}

Expand All @@ -53,7 +53,7 @@ public void AddAttribute_BeforeSpanFinished_IsSuccessful()
var childSpan = childScope.Span;
var spanLink = new SpanLink(parentSpan.Context);

childSpan.AddSpanLink(spanLink);
childSpan.AddLink(spanLink);
spanLink.AddAttribute("key", "value");

spanLink.Attributes.Should().BeEquivalentTo(new[] { new KeyValuePair<string, string>("key", "value") });
Expand Down

0 comments on commit 2bfad3d

Please sign in to comment.