Skip to content

Commit 7656bb9

Browse files
NicolappsConvex, Inc.
authored andcommitted
dash: show size of return value in logs (#41063)
GitOrigin-RevId: 74239f6a449b16f472fa7bf700ea8d8297fce053
1 parent c5a413d commit 7656bb9

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

crates/local_backend/src/logs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub enum FunctionExecutionJson {
5959
request_id: String,
6060
execution_id: String,
6161
usage_stats: JsonValue,
62+
return_bytes: Option<f64>,
6263
occ_info: Option<JsonValue>,
6364
execution_timestamp: f64,
6465
identity_type: String,
@@ -300,6 +301,7 @@ fn execution_to_json(
300301
.map(|id| id.to_string()),
301302
execution_id: execution.context.execution_id.to_string(),
302303
usage_stats: usage_stats_json,
304+
return_bytes: execution.return_bytes.map(|bytes| bytes as f64),
303305
occ_info: occ_info_json,
304306
execution_timestamp,
305307
identity_type,
@@ -332,6 +334,7 @@ fn execution_to_json(
332334
request_id: execution.context.request_id.to_string(),
333335
execution_id: execution.context.execution_id.to_string(),
334336
usage_stats: usage_stats_json,
337+
return_bytes: None, // Not supported in HTTP actions
335338
occ_info: occ_info_json,
336339
execution_timestamp,
337340
identity_type,

npm-packages/dashboard-common/src/features/logs/components/LogListResources.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import {
66
ChevronDownIcon,
77
ChevronUpIcon,
88
PieChartIcon,
9+
QuestionMarkCircledIcon,
910
} from "@radix-ui/react-icons";
11+
import { Tooltip } from "@ui/Tooltip";
1012
import { UsageStats } from "system-udfs/convex/_system/frontend/common";
1113

1214
type RequestUsageStats = UsageStats & {
1315
actionsRuntimeMs: number;
1416
actionComputeMbMs: number;
17+
returnBytes?: number;
1518
};
1619

1720
export function LogListResources({ logs }: { logs: UdfLog[] }) {
@@ -39,6 +42,9 @@ export function LogListResources({ logs }: { logs: UdfLog[] }) {
3942
ret[key] += value ?? 0;
4043
}
4144
}
45+
if ("returnBytes" in log && log.returnBytes) {
46+
ret.returnBytes = (ret.returnBytes ?? 0) + log.returnBytes;
47+
}
4248
if (
4349
log.kind === "outcome" &&
4450
(log.udfType === "Action" || log.udfType === "HttpAction")
@@ -129,6 +135,20 @@ export function LogListResources({ logs }: { logs: UdfLog[] }) {
129135
written
130136
</span>
131137
</li>
138+
{usageStats.returnBytes && (
139+
<li className="flex items-center justify-between py-2">
140+
<span className="flex items-center gap-1 text-center text-content-secondary">
141+
Return Value Size
142+
<Tooltip tip="Bandwidth from sending the return value of a function call to the user does not incur costs.">
143+
<QuestionMarkCircledIcon />
144+
</Tooltip>
145+
</span>
146+
<span className="text-content-primary">
147+
<strong>{formatBytes(usageStats.returnBytes)}</strong>{" "}
148+
returned
149+
</span>
150+
</li>
151+
)}
132152
</ul>
133153
{logs.filter((log) => log.kind === "outcome").length > 1 && (
134154
<div className="mt-3 text-content-secondary">

npm-packages/dashboard-common/src/lib/useLogs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export type UdfLogOutcome = {
6161
kind: "outcome";
6262
error?: string;
6363
usageStats?: UsageStats;
64+
returnBytes?: number;
6465
caller: string;
6566
environment: string;
6667
identityType: string;
@@ -178,6 +179,7 @@ export function processLogs(rawLogs: FunctionExecution[]): UdfLog[] {
178179
cachedResult: entry.cachedResult,
179180
kind: "outcome",
180181
usageStats: entry.usageStats,
182+
returnBytes: entry.returnBytes,
181183
caller: entry.caller,
182184
environment: entry.environment,
183185
identityType: entry.identityType,

npm-packages/system-udfs/convex/_system/frontend/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export type FunctionExecutionCompletion = {
6363
requestId: string;
6464
executionId: string;
6565
usageStats?: UsageStats;
66+
returnBytes?: number;
6667
caller: string;
6768
environment: string;
6869
identityType: string;

0 commit comments

Comments
 (0)