Skip to content
Merged
Changes from 2 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
14 changes: 12 additions & 2 deletions TUnit.Engine/Services/ObjectLifecycleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ private async Task InitializeTrackedObjectsAsync(TestContext testContext, Cancel
var tasks = new List<Task>(objectsAtLevel.Count);
foreach (var obj in objectsAtLevel)
{
tasks.Add(InitializeObjectWithSpanAsync(obj, testContext, cancellationToken));
// Tracked objects were discovered before execution and are already
// ordered deepest-first, so nested graph traversal would be redundant.
tasks.Add(InitializeObjectOnlyWithSpanAsync(obj, testContext, cancellationToken));
}

if (tasks.Count > 0)
Expand All @@ -268,12 +270,20 @@ private async Task InitializeTrackedObjectsAsync(TestContext testContext, Cancel

/// <summary>
/// Initializes an object and its nested objects, wrapped in a scope-aware OpenTelemetry span.
/// Used for objects outside the tracked graph, such as the test class instance.
/// </summary>
private async Task InitializeObjectWithSpanAsync(object obj, TestContext testContext, CancellationToken cancellationToken)
{
// First initialize nested objects depth-first
await InitializeNestedObjectsForExecutionAsync(obj, cancellationToken);
await InitializeObjectOnlyWithSpanAsync(obj, testContext, cancellationToken);
}

/// <summary>
/// Initializes only the supplied object, wrapped in a scope-aware OpenTelemetry span.
/// Callers that use this directly must initialize nested dependencies first.
/// </summary>
private async Task InitializeObjectOnlyWithSpanAsync(object obj, TestContext testContext, CancellationToken cancellationToken)
{
#if NET
var sharedType = TraceScopeRegistry.GetSharedType(obj);
var activitySource = TUnitActivitySource.GetSourceForSharedType(sharedType);
Expand Down
Loading