Skip to content
Merged
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions TUnit.Engine.Tests/HtmlReporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,48 @@ public async Task PublishArtifactAsync_Is_NoOp_When_MessageBus_Not_Injected()
}


[Test]
public void FilterAdditionalTraceIds_Removes_Primary_Trace_CaseInsensitive()
{
var primary = "abcdef0123456789abcdef0123456789";
var linked = "1111111111111111aaaaaaaaaaaaaaaa";
var all = new[] { primary.ToUpperInvariant(), linked };

var result = HtmlReporter.FilterAdditionalTraceIds(all, primary);

result.ShouldBe(new[] { linked });
}

[Test]
public void FilterAdditionalTraceIds_Returns_Input_When_Primary_Null()
{
var all = new[] { "aaaa", "bbbb" };

var result = HtmlReporter.FilterAdditionalTraceIds(all, primaryTraceId: null);

result.ShouldBeSameAs(all);
}

[Test]
public void FilterAdditionalTraceIds_Returns_Input_When_No_Match()
{
var all = new[] { "aaaa", "bbbb" };

var result = HtmlReporter.FilterAdditionalTraceIds(all, "cccc");

result.ShouldBeSameAs(all);
}

[Test]
public void FilterAdditionalTraceIds_Returns_Empty_When_Only_Primary()
{
var primary = "abcdef0123456789abcdef0123456789";

var result = HtmlReporter.FilterAdditionalTraceIds(new[] { primary }, primary);

result.ShouldBeEmpty();
}

[Test]
public async Task PublishArtifactAsync_Publishes_With_Correct_SessionUid()
{
Expand Down
26 changes: 25 additions & 1 deletion TUnit.Engine/Reporters/Html/HtmlReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private ReportData BuildReportData()
}

#if NET
var additionalTraceIds = TraceRegistry.GetTraceIds(kvp.Key);
var additionalTraceIds = FilterAdditionalTraceIds(TraceRegistry.GetTraceIds(kvp.Key), traceId);
string[]? additionalTraceIdsForResult = additionalTraceIds.Length > 0 ? additionalTraceIds : null;
#else
string[]? additionalTraceIdsForResult = null;
Expand Down Expand Up @@ -440,6 +440,30 @@ private static void AccumulateStatus(ReportSummary summary, ReportTestResult tes
}
}

#if NET
// The engine auto-registers the test's own traceId in TraceRegistry for OTLP correlation,
// so it shows up in GetTraceIds alongside any user-added traces. Strip it here so the
// primary trace (rendered as "Trace Timeline") isn't also rendered as a "Linked Trace".
internal static string[] FilterAdditionalTraceIds(string[] allTraceIds, string? primaryTraceId)
{
if (allTraceIds.Length == 0 || primaryTraceId is null)
{
return allTraceIds;
}

var filtered = new List<string>(allTraceIds.Length);
foreach (var tid in allTraceIds)
{
if (!string.Equals(tid, primaryTraceId, StringComparison.OrdinalIgnoreCase))
{
filtered.Add(tid);
}
}

return filtered.Count == allTraceIds.Length ? allTraceIds : filtered.ToArray();
}
#endif

private static ReportTestResult ExtractTestResult(string testId, TestNode testNode, string? traceId, string? spanId, int retryAttempt, string[]? additionalTraceIds)
{
IProperty? stateProperty = null;
Expand Down
Loading