Skip to content

feat: webhook analytics tab #7528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: ph/07-02-feat_webhooks_list_in_dashboard
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 43 additions & 29 deletions apps/dashboard/src/@/api/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import type {
UserOpStats,
WalletStats,
WalletUserStats,
WebhookLatencyStats,
WebhookRequestStats,
WebhookSummaryStats,
} from "@/types/analytics";
import { getAuthToken } from "./auth-token";
Expand Down Expand Up @@ -426,44 +428,56 @@ export async function getEngineCloudMethodUsage(
return json.data as EngineCloudStats[];
}

export async function getWebhookMetrics(params: {
teamId: string;
projectId: string;
webhookId: string;
period?: "day" | "week" | "month" | "year" | "all";
from?: Date;
to?: Date;
}): Promise<{ data: WebhookSummaryStats[] } | { error: string }> {
const searchParams = new URLSearchParams();

// Required params
searchParams.append("teamId", params.teamId);
searchParams.append("projectId", params.projectId);
export async function getWebhookSummary(
params: AnalyticsQueryParams & { webhookId: string },
): Promise<{ data: WebhookSummaryStats[] } | { error: string }> {
const searchParams = buildSearchParams(params);
searchParams.append("webhookId", params.webhookId);

// Optional params
if (params.period) {
searchParams.append("period", params.period);
}
if (params.from) {
searchParams.append("from", params.from.toISOString());
const res = await fetchAnalytics(
`v2/webhook/summary?${searchParams.toString()}`,
);
if (!res.ok) {
const reason = await res.text();
return { error: reason };
}
if (params.to) {
searchParams.append("to", params.to.toISOString());

return (await res.json()) as { data: WebhookSummaryStats[] };
}

export async function getWebhookRequests(
params: AnalyticsQueryParams & { webhookId?: string },
): Promise<{ data: WebhookRequestStats[] } | { error: string }> {
const searchParams = buildSearchParams(params);
if (params.webhookId) {
searchParams.append("webhookId", params.webhookId);
}

const res = await fetchAnalytics(
`v2/webhook/summary?${searchParams.toString()}`,
{
method: "GET",
},
`v2/webhook/requests?${searchParams.toString()}`,
);
if (!res.ok) {
const reason = await res.text();
return { error: reason };
}

return (await res.json()) as { data: WebhookRequestStats[] };
}

export async function getWebhookLatency(
params: AnalyticsQueryParams & { webhookId?: string },
): Promise<{ data: WebhookLatencyStats[] } | { error: string }> {
const searchParams = buildSearchParams(params);
if (params.webhookId) {
searchParams.append("webhookId", params.webhookId);
}
const res = await fetchAnalytics(
`v2/webhook/latency?${searchParams.toString()}`,
);
if (!res.ok) {
const reason = await res?.text();
const reason = await res.text();
return { error: reason };
}
return (await res.json()) as {
data: WebhookSummaryStats[];
};

return (await res.json()) as { data: WebhookLatencyStats[] };
}
16 changes: 0 additions & 16 deletions apps/dashboard/src/@/api/webhook-metrics.ts

This file was deleted.

17 changes: 16 additions & 1 deletion apps/dashboard/src/@/types/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,29 @@ export interface UniversalBridgeWalletStats {
developerFeeUsdCents: number;
}

export interface WebhookRequestStats {
date: string;
webhookId: string;
httpStatusCode: number;
totalRequests: number;
}

export interface WebhookLatencyStats {
date: string;
webhookId: string;
p50LatencyMs: number;
p90LatencyMs: number;
p99LatencyMs: number;
}

export interface WebhookSummaryStats {
webhookId: string;
totalRequests: number;
successRequests: number;
errorRequests: number;
successRate: number;
avgLatencyMs: number;
errorBreakdown: Record<string, unknown>;
errorBreakdown: Record<string, number>;
}

export interface AnalyticsQueryParams {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use server";

import { getWebhookSummary } from "@/api/analytics";
import type { WebhookSummaryStats } from "@/types/analytics";

export async function getWebhookSummaryAction(params: {
teamId: string;
projectId: string;
webhookId: string;
period?: "day" | "week" | "month" | "year" | "all";
from?: Date;
to?: Date;
}): Promise<WebhookSummaryStats | null> {
try {
const result = await getWebhookSummary(params);

if ("error" in result) {
console.error("Failed to fetch webhook summary:", result.error);
return null;
}

return result.data[0] ?? null;
} catch (error) {
console.error("Unexpected error fetching webhook summary:", error);
return null;
}
}
Loading
Loading