Skip to content
Open
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
11 changes: 1 addition & 10 deletions src/Aspire.Dashboard/Api/TelemetryApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,7 @@ internal sealed class TelemetryApiService(
/// </summary>
public TelemetryApiResponse? GetTrace(string traceId)
{
var result = telemetryRepository.GetTraces(new GetTracesRequest
{
ResourceKey = null,
StartIndex = 0,
Count = MaxQueryCount,
Filters = [],
FilterText = string.Empty
});

var trace = result.PagedResult.Items.FirstOrDefault(t => OtlpHelpers.MatchTelemetryId(t.TraceId, traceId));
var trace = telemetryRepository.GetTrace(traceId);
if (trace is null)
{
return null;
Expand Down
45 changes: 45 additions & 0 deletions tests/Aspire.Dashboard.Tests/TelemetryApiServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text;
using Aspire.Dashboard.Api;
using Aspire.Dashboard.Model;
using Aspire.Dashboard.Otlp.Model;
Expand Down Expand Up @@ -408,6 +409,50 @@ public async Task FollowLogsAsync_WithInvalidResourceName_ReturnsNoLogs()
Assert.Empty(receivedItems);
}

[Theory]
[InlineData("747261636531", true)] // full hex trace ID
[InlineData("7472616", true)] // shortened (7 char) prefix
[InlineData("747261", false)] // too short
[InlineData("nonexistent", false)]
public void GetTrace_VariousTraceIds_ReturnsExpectedResult(string lookupId, bool expectFound)
{
var repository = CreateRepository();
var traceId = Encoding.UTF8.GetString(Convert.FromHexString("747261636531"));

repository.AddTraces(new AddContext(), new RepeatedField<ResourceSpans>
{
new ResourceSpans
{
Resource = CreateResource(name: "service1", instanceId: "inst1"),
ScopeSpans =
{
new ScopeSpans
{
Scope = CreateScope(),
Spans =
{
CreateSpan(traceId: traceId, spanId: "span1", startTime: s_testTime, endTime: s_testTime.AddMinutes(1))
}
}
}
}
});

var service = CreateService(repository);

var result = service.GetTrace(lookupId);

if (expectFound)
{
Assert.NotNull(result);
Assert.Equal(1, result.ReturnedCount);
}
else
{
Assert.Null(result);
}
}

/// <summary>
/// Creates a TelemetryApiService instance for testing with optional custom dependencies.
/// </summary>
Expand Down
Loading