···11+-- Client Traffic Dashboard
22+-- Shows traffic breakdown by client type (SDK, MCP, browser)
33+-- Uses client_type and client_version attributes added via request_attributes_mapper
44+55+-- Main Dashboard: Traffic by Client Type
66+-- Shows request counts, latency, and error rates grouped by client source
77+-- Groups by client_type only (version shown in separate query for SDK/MCP)
88+WITH client_requests AS (
99+ SELECT
1010+ attributes->>'client_type' AS client_type,
1111+ span_name,
1212+ duration,
1313+ start_timestamp,
1414+ otel_status_code,
1515+ (attributes->>'http.status_code')::int AS status_code
1616+ FROM records
1717+ WHERE
1818+ kind = 'span'
1919+ AND attributes->>'client_type' IS NOT NULL
2020+ AND (span_name LIKE 'GET %' OR span_name LIKE 'POST %' OR span_name LIKE 'DELETE %' OR span_name LIKE 'PATCH %')
2121+)
2222+SELECT
2323+ client_type AS "Client Type",
2424+ COUNT(*) AS "Requests",
2525+ ROUND(AVG(duration * 1000)::numeric, 2) AS "Avg (ms)",
2626+ ROUND(PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY duration * 1000)::numeric, 2) AS "p95 (ms)",
2727+ COUNT(*) FILTER (WHERE status_code >= 400) AS "Errors",
2828+ ROUND((COUNT(*) FILTER (WHERE status_code >= 400)::numeric / NULLIF(COUNT(*), 0) * 100), 2) AS "Error %"
2929+FROM client_requests
3030+GROUP BY client_type
3131+ORDER BY COUNT(*) DESC;
3232+3333+3434+-- Alternative: Traffic Over Time by Client Type
3535+-- Uncomment to see hourly breakdown of traffic sources
3636+/*
3737+SELECT
3838+ DATE_TRUNC('hour', start_timestamp) AS "Hour",
3939+ attributes->>'client_type' AS "Client Type",
4040+ COUNT(*) AS "Requests",
4141+ ROUND(AVG(duration * 1000)::numeric, 2) AS "Avg (ms)"
4242+FROM records
4343+WHERE
4444+ kind = 'span'
4545+ AND attributes->>'client_type' IS NOT NULL
4646+ AND (span_name LIKE 'GET %' OR span_name LIKE 'POST %' OR span_name LIKE 'DELETE %')
4747+GROUP BY DATE_TRUNC('hour', start_timestamp), attributes->>'client_type'
4848+ORDER BY "Hour" DESC, "Requests" DESC
4949+LIMIT 100;
5050+*/
5151+5252+5353+-- Alternative: Top Endpoints by Client Type
5454+-- Uncomment to see which endpoints each client type uses most
5555+/*
5656+SELECT
5757+ attributes->>'client_type' AS "Client Type",
5858+ span_name AS "Endpoint",
5959+ COUNT(*) AS "Requests",
6060+ ROUND(AVG(duration * 1000)::numeric, 2) AS "Avg (ms)"
6161+FROM records
6262+WHERE
6363+ kind = 'span'
6464+ AND attributes->>'client_type' IS NOT NULL
6565+ AND (span_name LIKE 'GET %' OR span_name LIKE 'POST %' OR span_name LIKE 'DELETE %')
6666+GROUP BY attributes->>'client_type', span_name
6767+ORDER BY attributes->>'client_type', COUNT(*) DESC
6868+LIMIT 50;
6969+*/
7070+7171+7272+-- Alternative: SDK/MCP Version Distribution
7373+-- Uncomment to see version adoption for programmatic clients
7474+/*
7575+SELECT
7676+ attributes->>'client_type' AS "Client Type",
7777+ attributes->>'client_version' AS "Version",
7878+ COUNT(*) AS "Requests",
7979+ MIN(start_timestamp) AS "First Seen",
8080+ MAX(start_timestamp) AS "Last Seen"
8181+FROM records
8282+WHERE
8383+ kind = 'span'
8484+ AND attributes->>'client_type' IN ('sdk', 'mcp')
8585+ AND attributes->>'client_version' IS NOT NULL
8686+GROUP BY attributes->>'client_type', attributes->>'client_version'
8787+ORDER BY attributes->>'client_type', COUNT(*) DESC;
8888+*/
8989+9090+9191+-- Alternative: Recent SDK/MCP Requests (Debug View)
9292+-- Uncomment to see individual requests from programmatic clients
9393+/*
9494+SELECT
9595+ start_timestamp AS "Time",
9696+ attributes->>'client_type' AS "Client",
9797+ attributes->>'client_version' AS "Version",
9898+ span_name AS "Endpoint",
9999+ ROUND(duration * 1000, 2) AS "Duration (ms)",
100100+ (attributes->>'http.status_code')::int AS "Status"
101101+FROM records
102102+WHERE
103103+ kind = 'span'
104104+ AND attributes->>'client_type' IN ('sdk', 'mcp')
105105+ORDER BY start_timestamp DESC
106106+LIMIT 25;
107107+*/