diff --git a/tracer/src/Datadog.Trace/Activity/OtlpHelpers.cs b/tracer/src/Datadog.Trace/Activity/OtlpHelpers.cs index f95801dc5405..27958ce5f711 100644 --- a/tracer/src/Datadog.Trace/Activity/OtlpHelpers.cs +++ b/tracer/src/Datadog.Trace/Activity/OtlpHelpers.cs @@ -255,7 +255,7 @@ private static void ExtractActivityLinks(Span span, IActivity5? activity spanContext.PropagatedTags = traceTags; var spanLink = new SpanLink(spanContext); - span.AddSpanLink(spanLink); + span.AddLink(spanLink); if (duckLink.Tags is not null) { diff --git a/tracer/src/Datadog.Trace/Span.cs b/tracer/src/Datadog.Trace/Span.cs index e4b0a12fe00a..2c17e3c88886 100644 --- a/tracer/src/Datadog.Trace/Span.cs +++ b/tracer/src/Datadog.Trace/Span.cs @@ -539,16 +539,17 @@ private void WriteCloseDebugMessage() /// Adds a SpanLink to the current Span if the Span is active. /// /// The SpanLink to add - 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(); SpanLinks.Add(spanLink); + return this; } } } diff --git a/tracer/test/Datadog.Trace.Tests/Agent/MessagePack/SpanMessagePackFormatterTests.cs b/tracer/test/Datadog.Trace.Tests/Agent/MessagePack/SpanMessagePackFormatterTests.cs index 4660675dbcbe..2ed0d18d7335 100644 --- a/tracer/test/Datadog.Trace.Tests/Agent/MessagePack/SpanMessagePackFormatterTests.cs +++ b/tracer/test/Datadog.Trace.Tests/Agent/MessagePack/SpanMessagePackFormatterTests.cs @@ -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) { diff --git a/tracer/test/Datadog.Trace.Tests/SpanLinksTests.cs b/tracer/test/Datadog.Trace.Tests/SpanLinksTests.cs index 513b5352777b..55aeb08bbe0f 100644 --- a/tracer/test/Datadog.Trace.Tests/SpanLinksTests.cs +++ b/tracer/test/Datadog.Trace.Tests/SpanLinksTests.cs @@ -39,7 +39,7 @@ public void AddLink_AfterSpanFinished_IsNoOp() childSpan.Finish(); - childSpan.AddSpanLink(spanLink); + childSpan.AddLink(spanLink); childSpan.SpanLinks.Should().BeNullOrEmpty(); } @@ -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("key", "value") });