microsoft/aspire · error · InvalidOperationException

No trace found in OTLP data.

Error message

No trace found in OTLP data.

What it means

GetTraceJson serializes the first trace built from OTLP resource-spans data into a JSON string. It throws InvalidOperationException when GetTracesFromOtlpData yields no traces, meaning the supplied resourceSpans payload decoded to an empty collection so FirstOrDefault finds nothing.

Solutions

  1. Verify resourceSpans is non-null and contains at least one span before calling GetTraceJson
  2. Confirm the trace/span you expect exists (query the OTLP endpoint for the span ID first)
  3. Check that the telemetry source actually emitted spans for the requested resource/time window
  4. Treat 'trace not found' as a normal outcome in your flow and skip serialization for empty data

Example fix

// before
var json = SharedAIHelpers.GetTraceJson(resourceSpans, getResourceName);
// after
if (!SharedAIHelpers.GetTracesFromOtlpData(resourceSpans).Any())
{
    return; // or return an empty/placeholder response
}
var json = SharedAIHelpers.GetTraceJson(resourceSpans, getResourceName);
Defensive patterns

Strategy: validation

Validate before calling

var traces = SharedAIHelpers.GetTracesFromOtlpData(resourceSpans);
if (!traces.Any()) return null; // no trace decoded from OTLP data

Try / catch

try { return SharedAIHelpers.GetTraceJson(resourceSpans, getResourceName); }
catch (InvalidOperationException) { return null; /* trace not found */ }

Prevention

When it happens

Trigger: Calling GetTraceJson with null or empty resourceSpans, spans lists with no scopes/spans, or OTLP span JSON that maps to zero traces.

Common situations: Requesting a span/trace ID that was not captured; telemetry exporter had not flushed yet so the payload is empty; wrong resource passed to the AI trace-inspection helper.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/16cfc1b42263e524. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/ConsoleLogs/SharedAIHelpers.cs:142

        var tracesData = jsonArray.ToJsonString(s_jsonSerializerOptions);

        return (tracesData, limitMessage);
    }

    /// <summary>
    /// Converts OTLP resource spans to a single trace JSON for AI processing.
    /// </summary>
    /// <param name="resourceSpans">The OTLP resource spans containing trace data.</param>
    /// <param name="getResourceName">Optional function to resolve resource names.</param>
    /// <param name="dashboardBaseUrl">Optional dashboard URL.</param>
    /// <returns>The JSON string for the first trace.</returns>
    public static string GetTraceJson(
        IList<OtlpResourceSpansJson>? resourceSpans,
        Func<IOtlpResource, string> getResourceName,
        string? dashboardBaseUrl = null)
    {
        var traces = GetTracesFromOtlpData(resourceSpans);
        var trace = traces.FirstOrDefault() ?? throw new InvalidOperationException("No trace found in OTLP data.");
        var promptContext = new PromptContext();
        var dto = GetTraceDto(trace, promptContext, getResourceName, dashboardBaseUrl);

        return dto.ToJsonString(s_jsonSerializerOptions);
    }

    /// <summary>
    /// Serializes OTLP resource spans to a JSON string of individual spans for CLI output.
    /// Unlike <see cref="GetTracesJson"/>, which groups spans by trace ID, this returns a flat list.
    /// </summary>
    public static string SerializeSpansToJson(
        IList<OtlpResourceSpansJson>? resourceSpans,
        Func<IOtlpResource, string> getResourceName,
        string? dashboardBaseUrl = null)
    {
        var spans = GetSpanDtosFromOtlpData(resourceSpans);
        var context = new PromptContext(processValues: false);
        var jsonArray = new JsonArray(spans.Select(s => GetSpanDto(s, context, getResourceName, dashboardBaseUrl)).ToArray<JsonNode>());

View on GitHub (pinned to 25830f84bd)