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
13 changes: 12 additions & 1 deletion src/Aspire.Dashboard/Otlp/Model/OtlpTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public void AddSpan(OtlpSpan span)
if (!added)
{
Spans.Insert(0, span);

// If there isn't a root span then the first span is used as the trace name.
if (_rootSpan == null && !string.IsNullOrEmpty(span.ParentSpanId))
{
FullName = BuildFullName(span);
}
}

if (string.IsNullOrEmpty(span.ParentSpanId))
Expand All @@ -75,13 +81,18 @@ public void AddSpan(OtlpSpan span)
if (string.IsNullOrEmpty(existingSpan.ParentSpanId))
{
_rootSpan = existingSpan;
FullName = $"{existingSpan.Source.ApplicationName}: {existingSpan.Name}";
FullName = BuildFullName(existingSpan);
break;
}
}
}

AssertSpanOrder();

static string BuildFullName(OtlpSpan existingSpan)
{
return $"{existingSpan.Source.ApplicationName}: {existingSpan.Name}";
}
}

[Conditional("DEBUG")]
Expand Down
115 changes: 115 additions & 0 deletions tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/TraceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -944,4 +944,119 @@ public void GetTraces_MultipleInstances()
AssertId("2", trace.TraceId);
});
}

[Fact]
public void AddTraces_OutOfOrder_FullName()
{
// Arrange
var repository = CreateRepository();
var request = new GetTracesRequest
{
ApplicationKey = new ApplicationKey("TestService", "TestId"),
FilterText = string.Empty,
StartIndex = 0,
Count = 10
};

// Act 1
var addContext = new AddContext();
repository.AddTraces(addContext, new RepeatedField<ResourceSpans>()
{
new ResourceSpans
{
Resource = CreateResource(),
ScopeSpans =
{
new ScopeSpans
{
Scope = CreateScope(),
Spans =
{
CreateSpan(traceId: "1", spanId: "1-3", startTime: s_testTime.AddMinutes(10), endTime: s_testTime.AddMinutes(10), parentSpanId: "1-1")
}
}
}
}
});
Assert.Equal(0, addContext.FailureCount);

// Assert 1
var trace = Assert.Single(repository.GetTraces(request).PagedResult.Items);
Assert.Equal("TestService: Test span. Id: 1-3", trace.FullName);

// Act 2
repository.AddTraces(addContext, new RepeatedField<ResourceSpans>()
{
new ResourceSpans
{
Resource = CreateResource(),
ScopeSpans =
{
new ScopeSpans
{
Scope = CreateScope(),
Spans =
{
CreateSpan(traceId: "1", spanId: "1-2", startTime: s_testTime.AddMinutes(5), endTime: s_testTime.AddMinutes(10), parentSpanId: "1-1")
}
}
}
}
});
Assert.Equal(0, addContext.FailureCount);

// Assert 2
trace = Assert.Single(repository.GetTraces(request).PagedResult.Items);
Assert.Equal("TestService: Test span. Id: 1-2", trace.FullName);

// Act 3
repository.AddTraces(addContext, new RepeatedField<ResourceSpans>()
{
new ResourceSpans
{
Resource = CreateResource(),
ScopeSpans =
{
new ScopeSpans
{
Scope = CreateScope(),
Spans =
{
CreateSpan(traceId: "1", spanId: "1-1", startTime: s_testTime.AddMinutes(10), endTime: s_testTime.AddMinutes(10))
}
}
}
}
});
Assert.Equal(0, addContext.FailureCount);

// Assert 3
trace = Assert.Single(repository.GetTraces(request).PagedResult.Items);
Assert.Equal("TestService: Test span. Id: 1-1", trace.FullName);

// Act 4
repository.AddTraces(addContext, new RepeatedField<ResourceSpans>()
{
new ResourceSpans
{
Resource = CreateResource(),
ScopeSpans =
{
new ScopeSpans
{
Scope = CreateScope(),
Spans =
{
CreateSpan(traceId: "1", spanId: "1-4", startTime: s_testTime, endTime: s_testTime.AddMinutes(10), parentSpanId: "1-1")
}
}
}
}
});
Assert.Equal(0, addContext.FailureCount);

// Assert 4
trace = Assert.Single(repository.GetTraces(request).PagedResult.Items);
Assert.Equal("TestService: Test span. Id: 1-1", trace.FullName);
}
}
2 changes: 1 addition & 1 deletion tests/Shared/Telemetry/TelemetryTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static Span CreateSpan(string traceId, string spanId, DateTime startTime,
ParentSpanId = parentSpanId is null ? ByteString.Empty : ByteString.CopyFrom(Encoding.UTF8.GetBytes(parentSpanId)),
StartTimeUnixNano = DateTimeToUnixNanoseconds(startTime),
EndTimeUnixNano = DateTimeToUnixNanoseconds(endTime),
Name = "Test span"
Name = $"Test span. Id: {spanId}"
};
if (events != null)
{
Expand Down