Skip to content

Commit 2e6f0c4

Browse files
author
Timothy Mothra
authored
Merge branch 'main' into nullableattributes
2 parents 11ab58c + 27560f6 commit 2e6f0c4

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
* Added support to set `TraceState` when converting the
6+
System.Diagnostics.Activity object to its corresponding
7+
OpenTelemetry.Proto.Trace.V1.Span object.
8+
([#4331](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4331))
9+
510
## 1.5.0-alpha.1
611

712
Released 2023-Mar-07

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ internal static Span ToOtlpSpan(this Activity activity, SdkLimitOptions sdkLimit
143143
TraceId = UnsafeByteOperations.UnsafeWrap(traceIdBytes),
144144
SpanId = UnsafeByteOperations.UnsafeWrap(spanIdBytes),
145145
ParentSpanId = parentSpanIdString,
146+
TraceState = activity.TraceStateString ?? string.Empty,
146147

147148
StartTimeUnixNano = (ulong)startTimeUnixNano,
148149
EndTimeUnixNano = (ulong)(startTimeUnixNano + activity.Duration.ToNanoseconds()),

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,32 @@ public void ToOtlpSpanActivityStatusTakesPrecedenceOverStatusTagsWhenActivitySta
551551
Assert.Equal(StatusDescriptionOnError, otlpSpan.Status.Message);
552552
}
553553

554+
[Theory]
555+
[InlineData(true)]
556+
[InlineData(false)]
557+
public void ToOtlpSpanTraceStateTest(bool traceStateWasSet)
558+
{
559+
using var activitySource = new ActivitySource(nameof(this.ToOtlpSpanTest));
560+
using var activity = activitySource.StartActivity("Name");
561+
string tracestate = "a=b;c=d";
562+
if (traceStateWasSet)
563+
{
564+
activity.TraceStateString = tracestate;
565+
}
566+
567+
var otlpSpan = activity.ToOtlpSpan(DefaultSdkLimitOptions);
568+
569+
if (traceStateWasSet)
570+
{
571+
Assert.NotNull(otlpSpan.TraceState);
572+
Assert.Equal(tracestate, otlpSpan.TraceState);
573+
}
574+
else
575+
{
576+
Assert.Equal(string.Empty, otlpSpan.TraceState);
577+
}
578+
}
579+
554580
[Fact]
555581
public void ToOtlpSpanPeerServiceTest()
556582
{

0 commit comments

Comments
 (0)