Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing test for StartRootSpan #2878

Merged
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
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