Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* Added support to set `TraceState` when converting the
System.Diagnostics.Activity object to its corresponding
OpenTelemetry.Proto.Trace.V1.Span object.
([#4331](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4331))

## 1.5.0-alpha.1

Released 2023-Mar-07
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ internal static Span ToOtlpSpan(this Activity activity, SdkLimitOptions sdkLimit
TraceId = UnsafeByteOperations.UnsafeWrap(traceIdBytes),
SpanId = UnsafeByteOperations.UnsafeWrap(spanIdBytes),
ParentSpanId = parentSpanIdString,
TraceState = activity.TraceStateString ?? string.Empty,

StartTimeUnixNano = (ulong)startTimeUnixNano,
EndTimeUnixNano = (ulong)(startTimeUnixNano + activity.Duration.ToNanoseconds()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,32 @@ public void ToOtlpSpanActivityStatusTakesPrecedenceOverStatusTagsWhenActivitySta
Assert.Equal(StatusDescriptionOnError, otlpSpan.Status.Message);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void ToOtlpSpanTraceStateTest(bool traceStateWasSet)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have existing tests for checking other things from activity context? like spanid,traceid etc? we could just modify it instead of adding dedicated tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add traceState assertions to ToOtlpSpanTest.
Personally, I prefer to keep unit tests small.

{
using var activitySource = new ActivitySource(nameof(this.ToOtlpSpanTest));
using var activity = activitySource.StartActivity("Name");
string tracestate = "a=b;c=d";
if (traceStateWasSet)
{
activity.TraceStateString = tracestate;
}

var otlpSpan = activity.ToOtlpSpan(DefaultSdkLimitOptions);

if (traceStateWasSet)
{
Assert.NotNull(otlpSpan.TraceState);
Assert.Equal(tracestate, otlpSpan.TraceState);
}
else
{
Assert.Equal(string.Empty, otlpSpan.TraceState);
}
}

[Fact]
public void ToOtlpSpanPeerServiceTest()
{
Expand Down