From 0946b08674a3e4c24c6a1deea81e9fde5c00ea17 Mon Sep 17 00:00:00 2001 From: Yun-Ting Date: Fri, 24 Mar 2023 11:41:28 -0700 Subject: [PATCH 1/4] initial --- .../Implementation/ActivityExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs index b76ac227cd6..23bf82cb24a 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs @@ -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()), From c9835660f92278e819db56dbea82ab29b8d0653f Mon Sep 17 00:00:00 2001 From: Yun-Ting Date: Fri, 24 Mar 2023 12:05:29 -0700 Subject: [PATCH 2/4] test --- .../OtlpTraceExporterTests.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs index a3003baf8a7..0dda7611a59 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs @@ -551,6 +551,32 @@ public void ToOtlpSpanActivityStatusTakesPrecedenceOverStatusTagsWhenActivitySta Assert.Equal(StatusDescriptionOnError, otlpSpan.Status.Message); } + [Theory] + [InlineData(true)] + [InlineData(false)] + public void ToOtlpSpanTraceStateTest(bool traceStateWasSet) + { + 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.True(string.IsNullOrEmpty(otlpSpan.TraceState)); + } + } + [Fact] public void ToOtlpSpanPeerServiceTest() { From b7fc5c64cff7a0fa5fab867a9f51a89eef05a6fa Mon Sep 17 00:00:00 2001 From: Yun-Ting Date: Fri, 24 Mar 2023 12:13:14 -0700 Subject: [PATCH 3/4] changelog --- .../CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index 7fad8554f47..0afaba4da4c 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -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 From afa7cf0e04f12d04aaa59005197aa27472e75def Mon Sep 17 00:00:00 2001 From: Yun-Ting Date: Fri, 24 Mar 2023 14:59:47 -0700 Subject: [PATCH 4/4] comment --- .../OtlpTraceExporterTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs index 0dda7611a59..db156c005b7 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs @@ -573,7 +573,7 @@ public void ToOtlpSpanTraceStateTest(bool traceStateWasSet) } else { - Assert.True(string.IsNullOrEmpty(otlpSpan.TraceState)); + Assert.Equal(string.Empty, otlpSpan.TraceState); } }