Skip to content

Commit

Permalink
Add failing test for StartRootSpan (#2878)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwest authored Feb 9, 2022
1 parent 7ce2e4c commit b1d57e9
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/OpenTelemetry.Tests/Trace/TracerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// </copyright>

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Xunit;

namespace OpenTelemetry.Trace.Tests
Expand Down Expand Up @@ -74,6 +76,45 @@ public void Tracer_StartRootSpan_BadArgs_NullSpanName()
Assert.Null(span3.Activity.DisplayName);
}

[Fact(Skip = "See https://github.com/open-telemetry/opentelemetry-dotnet/issues/2803")]
public async Task Tracer_StartRootSpan_StartsNewTrace()
{
var exportedItems = new List<Activity>();

using var tracer = Sdk.CreateTracerProviderBuilder()
.AddSource("tracername")
.AddInMemoryExporter(exportedItems)
.Build();

async Task DoSomeAsyncWork()
{
await Task.Delay(10);
using (tracer.GetTracer("tracername").StartRootSpan("RootSpan2"))
{
await Task.Delay(10);
}
}

using (tracer.GetTracer("tracername").StartActiveSpan("RootSpan1"))
{
await DoSomeAsyncWork();
}

Assert.Equal(2, exportedItems.Count);

var rootSpan2 = exportedItems[0];
var rootSpan1 = exportedItems[1];
Assert.Equal("RootSpan2", rootSpan2.DisplayName);
Assert.Equal("RootSpan1", rootSpan1.DisplayName);
Assert.Equal(default(ActivitySpanId), rootSpan1.ParentSpanId);

// This is where this test currently fails
// rootSpan2 should be a root span of a new trace and not a child of rootSpan1
Assert.Equal(default(ActivitySpanId), rootSpan2.ParentSpanId);
Assert.NotEqual(rootSpan2.TraceId, rootSpan1.TraceId);
Assert.NotEqual(rootSpan2.ParentSpanId, rootSpan1.SpanId);
}

[Fact]
public void Tracer_StartSpan_BadArgs_NullSpanName()
{
Expand Down

0 comments on commit b1d57e9

Please sign in to comment.