Unverified Commit f6e11e86 authored by Hong Minhee's avatar Hong Minhee
Browse files

Fix getRecentTraces sorting/limiting logic

Collect all summaries before sorting and limiting to ensure we return
the actual most recent traces, not just the first N traces returned
by KvStore.list().

Also removed unnecessary type annotation on summaryPrefix.

https://github.com/fedify-dev/fedify/pull/502#discussion_r2642993269
https://github.com/fedify-dev/fedify/pull/502#discussion_r2642989826
parent d9aea3f7
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -547,15 +547,12 @@ export class FedifySpanExporter implements SpanExporter {
  async getRecentTraces(
    options?: GetRecentTracesOptions,
  ): Promise<TraceSummary[]> {
    const summaryPrefix: KvKey = [...this.#keyPrefix, "_summaries"] as KvKey;
    const summaryPrefix = [...this.#keyPrefix, "_summaries"] as KvKey;
    const summaries: TraceSummary[] = [];

    if (this.#kv.list != null) {
      for await (const entry of this.#kv.list(summaryPrefix)) {
        summaries.push(entry.value as TraceSummary);
        if (options?.limit != null && summaries.length >= options.limit) {
          break;
        }
      }
    }