Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Capture and display query params in API request logs

Kiran K2554626b2cf8
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/logs/[logId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/logs/[logId]/page-client.tsx
index b64d2d4a19..7f171d3db7 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/logs/[logId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/logs/[logId]/page-client.tsx
@@ -97,6 +97,7 @@ function LogDetailContent({ log }: { log: EnrichedApiLog }) {
const [highlightedBodies, setHighlightedBodies] = useState<{
request: string;
response: string;
+ queryParams: string;
} | null>(null);
useEffect(() => {
@@ -133,6 +134,10 @@ function LogDetailContent({ log }: { log: EnrichedApiLog }) {
theme: "min-light",
lang: "json",
}),
+ queryParams: highlighter.codeToHtml(toJsonString(log.query_params), {
+ theme: "min-light",
+ lang: "json",
+ }),
});
}, [highlighter, log]);
@@ -227,6 +232,19 @@ function LogDetailContent({ log }: { log: EnrichedApiLog }) {
</div>
)}
</div>
+ {log.query_params && (
+ <div className="flex flex-col gap-2">
+ <h3 className="text-content-emphasis text-lg font-semibold">
+ Query parameters
+ </h3>
+ <div
+ className="shiki-wrapper max-h-[800px] overflow-auto rounded-xl border border-neutral-200 bg-white p-4 text-sm"
+ dangerouslySetInnerHTML={{
+ __html: highlightedBodies.queryParams,
+ }}
+ />
+ </div>
+ )}
{log.method !== "DELETE" && (
<div className="flex flex-col gap-2">
<h3 className="text-content-emphasis text-lg font-semibold">
diff --git a/apps/web/lib/api-logs/capture-request-log.ts b/apps/web/lib/api-logs/capture-request-log.ts
index 80eed2eacf..3be4fbdb28 100644
--- a/apps/web/lib/api-logs/capture-request-log.ts
+++ b/apps/web/lib/api-logs/capture-request-log.ts
@@ -83,6 +83,9 @@ export async function captureRequestLog({
responseBody = await responseClone.json();
} catch {}
+ const queryParams =
+ url.searchParams.size > 0 ? Object.fromEntries(url.searchParams) : null;
+
// Mask sensitive fields in the response body
if (responseBody) {
const sensitiveResponseFields =
@@ -105,6 +108,7 @@ export async function captureRequestLog({
duration,
userAgent: requestHeaders.get("user-agent"),
requestBody,
+ queryParams,
responseBody,
tokenId: token?.id ?? null,
userId: session?.user?.id ?? null,
diff --git a/apps/web/lib/api-logs/record-api-log.ts b/apps/web/lib/api-logs/record-api-log.ts
index b6fafd0df7..99262f3502 100644
--- a/apps/web/lib/api-logs/record-api-log.ts
+++ b/apps/web/lib/api-logs/record-api-log.ts
@@ -20,6 +20,7 @@ type RecordApiLogParams = {
duration: number;
userAgent: string | null;
requestBody: unknown;
+ queryParams?: unknown;
responseBody: unknown;
tokenId: string | null;
userId: string | null;
@@ -41,6 +42,7 @@ export const recordApiLog = async ({
duration,
userAgent,
requestBody,
+ queryParams,
responseBody,
tokenId,
userId,
@@ -57,6 +59,7 @@ export const recordApiLog = async ({
duration,
user_agent: userAgent ?? "",
request_body: JSON.stringify(requestBody),
+ query_params: queryParams ? JSON.stringify(queryParams) : "",
response_body: JSON.stringify(responseBody),
token_id: tokenId ?? "",
user_id: userId ?? "",
diff --git a/apps/web/lib/api-logs/schemas.ts b/apps/web/lib/api-logs/schemas.ts
index 2a113d3691..81e3448e47 100644
--- a/apps/web/lib/api-logs/schemas.ts
+++ b/apps/web/lib/api-logs/schemas.ts
@@ -17,6 +17,7 @@ export const apiLogSchemaTB = z.object({
duration: z.number(),
user_agent: z.string(),
request_body: z.string(),
+ query_params: z.string(),
response_body: z.string(),
token_id: z.string(),
user_id: z.string(),
diff --git a/packages/tinybird/datasources/dub_api_logs.datasource b/packages/tinybird/datasources/dub_api_logs.datasource
index 53fb77bedc..9b179ba127 100644
--- a/packages/tinybird/datasources/dub_api_logs.datasource
+++ b/packages/tinybird/datasources/dub_api_logs.datasource
@@ -11,6 +11,7 @@ SCHEMA >
`duration` UInt32 `json:$.duration`,
`user_agent` String `json:$.user_agent`,
`request_body` String `json:$.request_body`,
+ `query_params` String `json:$.query_params`,
`response_body` String `json:$.response_body`,
`token_id` String `json:$.token_id`,
`user_id` String `json:$.user_id`,
diff --git a/packages/tinybird/datasources/dub_api_logs_id.datasource b/packages/tinybird/datasources/dub_api_logs_id.datasource
index b5e8342a29..bbb46c9708 100644
--- a/packages/tinybird/datasources/dub_api_logs_id.datasource
+++ b/packages/tinybird/datasources/dub_api_logs_id.datasource
@@ -11,6 +11,7 @@ SCHEMA >
`duration` UInt32,
`user_agent` String,
`request_body` String,
+ `query_params` String,
`response_body` String,
`token_id` String,
`user_id` String,
diff --git a/packages/tinybird/pipes/get_api_log_by_id.pipe b/packages/tinybird/pipes/get_api_log_by_id.pipe
index 408e796663..2cc86dce37 100644
--- a/packages/tinybird/pipes/get_api_log_by_id.pipe
+++ b/packages/tinybird/pipes/get_api_log_by_id.pipe
@@ -11,6 +11,7 @@ SQL >
duration,
user_agent,
request_body,
+ query_params,
response_body,
token_id,
user_id,
diff --git a/packages/tinybird/pipes/get_api_logs.pipe b/packages/tinybird/pipes/get_api_logs.pipe
index 44856eac7a..635777bd76 100644
--- a/packages/tinybird/pipes/get_api_logs.pipe
+++ b/packages/tinybird/pipes/get_api_logs.pipe
@@ -11,6 +11,7 @@ SQL >
duration,
user_agent,
request_body,
+ query_params,
response_body,
token_id,
user_id,