{"record":{"id":"16cfc1b42263e524","repo":"microsoft/aspire","slug":"no-trace-found-in-otlp-data","errorCode":null,"errorMessage":"No trace found in OTLP data.","messagePattern":"No trace found in OTLP data\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Shared/ConsoleLogs/SharedAIHelpers.cs","lineNumber":142,"sourceCode":"        var tracesData = jsonArray.ToJsonString(s_jsonSerializerOptions);\n\n        return (tracesData, limitMessage);\n    }\n\n    /// <summary>\n    /// Converts OTLP resource spans to a single trace JSON for AI processing.\n    /// </summary>\n    /// <param name=\"resourceSpans\">The OTLP resource spans containing trace data.</param>\n    /// <param name=\"getResourceName\">Optional function to resolve resource names.</param>\n    /// <param name=\"dashboardBaseUrl\">Optional dashboard URL.</param>\n    /// <returns>The JSON string for the first trace.</returns>\n    public static string GetTraceJson(\n        IList<OtlpResourceSpansJson>? resourceSpans,\n        Func<IOtlpResource, string> getResourceName,\n        string? dashboardBaseUrl = null)\n    {\n        var traces = GetTracesFromOtlpData(resourceSpans);\n        var trace = traces.FirstOrDefault() ?? throw new InvalidOperationException(\"No trace found in OTLP data.\");\n        var promptContext = new PromptContext();\n        var dto = GetTraceDto(trace, promptContext, getResourceName, dashboardBaseUrl);\n\n        return dto.ToJsonString(s_jsonSerializerOptions);\n    }\n\n    /// <summary>\n    /// Serializes OTLP resource spans to a JSON string of individual spans for CLI output.\n    /// Unlike <see cref=\"GetTracesJson\"/>, which groups spans by trace ID, this returns a flat list.\n    /// </summary>\n    public static string SerializeSpansToJson(\n        IList<OtlpResourceSpansJson>? resourceSpans,\n        Func<IOtlpResource, string> getResourceName,\n        string? dashboardBaseUrl = null)\n    {\n        var spans = GetSpanDtosFromOtlpData(resourceSpans);\n        var context = new PromptContext(processValues: false);\n        var jsonArray = new JsonArray(spans.Select(s => GetSpanDto(s, context, getResourceName, dashboardBaseUrl)).ToArray<JsonNode>());","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Shared/ConsoleLogs/SharedAIHelpers.cs#L124-L160","documentation":"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.","triggerScenarios":"Calling GetTraceJson with null or empty resourceSpans, spans lists with no scopes/spans, or OTLP span JSON that maps to zero traces.","commonSituations":"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.","solutions":["Verify resourceSpans is non-null and contains at least one span before calling GetTraceJson","Confirm the trace/span you expect exists (query the OTLP endpoint for the span ID first)","Check that the telemetry source actually emitted spans for the requested resource/time window","Treat 'trace not found' as a normal outcome in your flow and skip serialization for empty data"],"exampleFix":"// before\nvar json = SharedAIHelpers.GetTraceJson(resourceSpans, getResourceName);\n// after\nif (!SharedAIHelpers.GetTracesFromOtlpData(resourceSpans).Any())\n{\n    return; // or return an empty/placeholder response\n}\nvar json = SharedAIHelpers.GetTraceJson(resourceSpans, getResourceName);","handlingStrategy":"validation","validationCode":"var traces = SharedAIHelpers.GetTracesFromOtlpData(resourceSpans);\nif (!traces.Any()) return null; // no trace decoded from OTLP data","typeGuard":null,"tryCatchPattern":"try { return SharedAIHelpers.GetTraceJson(resourceSpans, getResourceName); }\ncatch (InvalidOperationException) { return null; /* trace not found */ }","preventionTips":["Verify the span/trace ID exists via the OTLP endpoint before serializing","Ensure exporters have flushed telemetry before reading","Treat missing traces as a normal, handled outcome"],"tags":["otlp","traces","empty-data","invalid-operation"],"backgroundTag":"empty-result-set","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}