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
17 changes: 14 additions & 3 deletions src/Aspire.Dashboard/Otlp/Model/OtlpTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@ public int CalculateDepth(OtlpSpan span)

public void AddSpan(OtlpSpan span)
{
Spans.Add(span);
// TODO: Optimize to insert at the right position.
Spans.Sort(SpanStartDateComparer.Instance);
var added = false;
for (var i = Spans.Count - 1; i >= 0; i--)
{
if (span.StartTime > Spans[i].StartTime)
{
Spans.Insert(i + 1, span);
added = true;
break;
}
}
if (!added)
{
Spans.Insert(0, span);
}

if (string.IsNullOrEmpty(span.ParentSpanId))
{
Expand Down
23 changes: 18 additions & 5 deletions src/Aspire.Dashboard/Otlp/Storage/TelemetryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,24 @@ public void AddLogsCore(AddContext context, OtlpApplication application, Repeate
try
{
var logEntry = new OtlpLogEntry(record, application);
_logs.Add(logEntry);

// Insert log entry in the correct position based on timestamp.
// Logs can be added out of order by different services.
var added = false;
for (var i = _logs.Count - 1; i >= 0; i--)
{
if (logEntry.TimeStamp > _logs[i].TimeStamp)
{
_logs.Insert(i + 1, logEntry);
added = true;
break;
}
}
if (!added)
{
_logs.Insert(0, logEntry);
}

foreach (var kvp in logEntry.Properties)
{
_logPropertyKeys.Add((application, kvp.Key));
Expand All @@ -204,9 +221,6 @@ public void AddLogsCore(AddContext context, OtlpApplication application, Repeate
}
}
}

// TODO: Insert logs into the right location instead of sorting everything.
_logs.Sort((a, b) => a.TimeStamp.CompareTo(b.TimeStamp));
}
finally
{
Expand Down Expand Up @@ -452,7 +466,6 @@ internal void AddTracesCore(AddContext context, OtlpApplication application, Rep
if (newTrace)
{
var added = false;
var position = _traces.Count;
for (var i = _traces.Count - 1; i >= 0; i--)
{
var currentTrace = _traces[i];
Expand Down
Loading