set `TraceState` field in OTLP Exporter (#4331)
This commit is contained in:
parent
094124e9ee
commit
27560f6267
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation
|
|||
TraceId = UnsafeByteOperations.UnsafeWrap(traceIdBytes),
|
||||
SpanId = UnsafeByteOperations.UnsafeWrap(spanIdBytes),
|
||||
ParentSpanId = parentSpanIdString,
|
||||
TraceState = activity.TraceStateString ?? string.Empty,
|
||||
|
||||
StartTimeUnixNano = (ulong)startTimeUnixNano,
|
||||
EndTimeUnixNano = (ulong)(startTimeUnixNano + activity.Duration.ToNanoseconds()),
|
||||
|
|
|
|||
|
|
@ -551,6 +551,32 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
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.Equal(string.Empty, otlpSpan.TraceState);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToOtlpSpanPeerServiceTest()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue