Skip to content

Commit 3d51324

Browse files
committed
improve log streaming
1 parent c3d7d0e commit 3d51324

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

main.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ const logsCommand = new Command<{ endpoint: string }>()
153153

154154
const trpcClient = createTrpcClient(options.endpoint);
155155

156+
const seenIds = new Set();
157+
let onceConnected = false;
158+
156159
// deno-lint-ignore no-explicit-any
157160
const sub = (trpcClient.apps as any).logs.subscribe({
158161
org: gottenApp.org,
@@ -164,9 +167,20 @@ const logsCommand = new Command<{ endpoint: string }>()
164167
}, {
165168
onData: (data: "streaming" | null | LogEntry[]) => {
166169
if (data === "streaming") {
167-
console.log("Streaming logs...");
170+
if (!onceConnected) {
171+
console.log("connected, streaming logs...");
172+
}
173+
onceConnected = true;
168174
} else if (Array.isArray(data)) {
169175
for (const log of data) {
176+
const id = log.LogAttributes["log.record.uid"];
177+
178+
if (seenIds.has(id)) {
179+
continue;
180+
} else {
181+
seenIds.add(id);
182+
}
183+
170184
let text = `[${renderTemporalTimestamp(log.Timestamp)}${
171185
log.TraceId ? ` (${log.TraceId})` : ""
172186
}] ${log.Body}`;

0 commit comments

Comments
 (0)