The only tool you need to know what is happening and how to fix it.
Go alertingexception-trackerissue-trackinglogsmetricsmonitoringobservability-platformopen-telemetryotelsession-replaytelemetrytraces
better endpoints charts
dduxb5bc09d7c877
diff --git a/frontend/src/lib/components/dashboard/d3-horizontal-bar-chart.svelte b/frontend/src/lib/components/dashboard/d3-horizontal-bar-chart.sveltenew file mode 100644index 00000000..03a6a496--- /dev/null+++ b/frontend/src/lib/components/dashboard/d3-horizontal-bar-chart.svelte@@ -0,0 +1,187 @@+<script lang="ts">+ import { scaleLinear, scaleBand } from 'd3-scale';+ import { max } from 'd3-array';++ type BarData = {+ endpoint: string;+ value: number;+ };++ let {+ data = [],+ height = 220,+ padding = { top: 10, right: 70, bottom: 10, left: 160 },+ unit = 'ms',+ formatValue+ } = $props<{+ data: BarData[];+ height?: number;+ padding?: { top: number; right: number; bottom: number; left: number };+ unit?: string;+ formatValue?: (value: number) => string;+ }>();++ // Chart colors using CSS variables+ const chartColors = [+ 'var(--chart-1)',+ 'var(--chart-2)',+ 'var(--chart-3)',+ 'var(--chart-4)',+ 'var(--chart-5)',+ 'hsl(280, 65%, 60%)',+ 'hsl(200, 65%, 55%)',+ 'hsl(340, 65%, 55%)'+ ];++ let containerRef = $state<HTMLDivElement | null>(null);+ let width = $state(400);++ // Hover state for tooltip+ let hoveredIndex = $state<number | null>(null);++ // Observe container width+ $effect(() => {+ if (!containerRef) return;++ const observer = new ResizeObserver((entries) => {+ for (const entry of entries) {+ width = entry.contentRect.width;+ }+ });++ observer.observe(containerRef);+ return () => observer.disconnect();+ });++ // Chart dimensions+ const chartWidth = $derived(Math.max(0, width - padding.left - padding.right));+ const chartHeight = $derived(Math.max(0, height - padding.top - padding.bottom));++ // Sort data by value descending (worst at top)+ const sortedData = $derived(+ [...data].sort((a, b) => b.value - a.value)+ );++ // Calculate max value for scale+ const maxValue = $derived(max(sortedData, d => d.value) ?? 0);++ // X scale (value)+ const xScale = $derived(+ scaleLinear()+ .domain([0, maxValue * 1.1 || 1])+ .range([0, chartWidth])+ );++ // Y scale (endpoints)+ const yScale = $derived(+ scaleBand<string>()+ .domain(sortedData.map(d => d.endpoint))+ .range([0, chartHeight])+ .padding(0.25)+ );++ const barHeight = $derived(yScale.bandwidth());+ const hasData = $derived(sortedData.length > 0);++ // Format value for display+ function formatDisplayValue(value: number): string {+ if (formatValue) return formatValue(value);+ if (value >= 1000) {+ return `${(value / 1000).toFixed(1)}s`;+ }+ return `${Math.round(value)}${unit}`;+ }++ // Truncate endpoint name for display+ function truncateEndpoint(endpoint: string, maxLen: number = 22): string {+ if (endpoint.length <= maxLen) return endpoint;+ return endpoint.slice(0, maxLen - 3) + '...';+ }++ function handleLabelMouseEnter(index: number) {+ hoveredIndex = index;+ }++ function handleLabelMouseLeave() {+ hoveredIndex = null;+ }+</script>++<div+ bind:this={containerRef}+ class="relative w-full"+ style="height: {height}px;"+>+ {#if hasData && chartWidth > 0}+ <svg {width} {height}>+ <g transform="translate({padding.left}, {padding.top})">+ <!-- Bars -->+ {#each sortedData as item, i}+ {@const y = yScale(item.endpoint) ?? 0}+ {@const barWidth = xScale(item.value)}+ {@const color = chartColors[i % chartColors.length]}+ {@const isTruncated = item.endpoint.length > 22}++ <!-- Bar -->+ <rect+ x={0}+ {y}+ width={Math.max(0, barWidth)}+ height={barHeight}+ fill={color}+ fill-opacity="0.85"+ rx="3"+ ry="3"+ />++ <!-- Endpoint label (left side) -->+ <text+ x={-8}+ y={y + barHeight / 2}+ text-anchor="end"+ dominant-baseline="middle"+ fill="currentColor"+ class="text-muted-foreground"+ font-size="11"+ style="cursor: default;"+ onmouseenter={() => isTruncated && handleLabelMouseEnter(i)}+ onmouseleave={handleLabelMouseLeave}+ >+ {truncateEndpoint(item.endpoint)}+ </text>++ <!-- Value label (right of bar) -->+ <text+ x={barWidth + 8}+ y={y + barHeight / 2}+ text-anchor="start"+ dominant-baseline="middle"+ fill="currentColor"+ class="text-foreground"+ font-size="11"+ font-weight="500"+ style="cursor: default;"+ >+ {formatDisplayValue(item.value)}+ </text>+ {/each}+ </g>+ </svg>++ <!-- Expanded label tooltip -->+ {#if hoveredIndex !== null}+ {@const item = sortedData[hoveredIndex]}+ {@const y = (yScale(item.endpoint) ?? 0) + padding.top + barHeight / 2}+ <div+ class="absolute z-10 pointer-events-none bg-background border border-border rounded px-2 py-1 text-xs text-muted-foreground whitespace-nowrap shadow-sm"+ style="right: {width - padding.left + 8}px; top: {y}px; transform: translateY(-50%);"+ >+ {item.endpoint}+ </div>+ {/if}+ {:else}+ <div class="flex h-full items-center justify-center text-sm text-muted-foreground">+ No data available+ </div>+ {/if}+</div>diff --git a/frontend/src/lib/components/dashboard/d3-stacked-area-chart.svelte b/frontend/src/lib/components/dashboard/d3-stacked-area-chart.svelteindex 09446548..89e5da26 100644--- a/frontend/src/lib/components/dashboard/d3-stacked-area-chart.svelte+++ b/frontend/src/lib/components/dashboard/d3-stacked-area-chart.svelte@@ -22,7 +22,8 @@height = 220,padding = { top: 10, right: 4, bottom: 20, left: 55 },unit = 'ms',- formatValue+ formatValue,+ onRangeSelect} = $props<{endpoints: string[];series: DataPoint[];@@ -30,6 +31,7 @@padding?: { top: number; right: number; bottom: number; left: number };unit?: string;formatValue?: (value: number) => string;+ onRangeSelect?: (from: Date, to: Date) => void;}>();const tz = $derived(getTimezone());@@ -51,6 +53,11 @@let isHovering = $state(false);let mouseX = $state(0);+ // Drag selection state+ let isDragging = $state(false);+ let dragStartX = $state(0);+ let dragEndX = $state(0);+// Observe container width$effect(() => {if (!containerRef) return;@@ -197,6 +204,13 @@return new Date(xMin().getTime() + timeDiff * percentage);}+ // Selection region computed values+ const selectionLeft = $derived(Math.max(padding.left, Math.min(dragStartX, dragEndX)));+ const selectionRight = $derived(Math.min(width - padding.right, Math.max(dragStartX, dragEndX)));+ const selectionWidth = $derived(selectionRight - selectionLeft);+ const selectionStartTime = $derived(getTimeAtPosition(selectionLeft));+ const selectionEndTime = $derived(getTimeAtPosition(selectionLeft + selectionWidth));+// Find the closest data point to a given timefunction getDataAtTime(time: Date): StackedData | null {const data = stackedData();@@ -244,6 +258,10 @@if (!containerRef) return;const rect = containerRef.getBoundingClientRect();mouseX = e.clientX - rect.left;++ if (isDragging) {+ dragEndX = mouseX;+ }}function handleMouseEnter() {@@ -252,8 +270,49 @@function handleMouseLeave() {isHovering = false;+ if (isDragging) isDragging = false;+ }++ function handleMouseDown(e: MouseEvent) {+ if (!containerRef || e.button !== 0) return;+ const rect = containerRef.getBoundingClientRect();+ const x = e.clientX - rect.left;++ if (x < padding.left || x > rect.width - padding.right) return;++ isDragging = true;+ dragStartX = x;+ dragEndX = x;+ e.preventDefault();+ }++ function handleMouseUp() {+ if (!isDragging) return;++ isDragging = false;++ if (selectionWidth > 10 && onRangeSelect) {+ const startTime = getTimeAtPosition(Math.min(dragStartX, dragEndX));+ const endTime = getTimeAtPosition(Math.max(dragStartX, dragEndX));+ onRangeSelect(startTime, endTime);+ }}+ function handleKeydown(e: KeyboardEvent) {+ if (e.key === 'Escape' && isDragging) {+ isDragging = false;+ dragStartX = 0;+ dragEndX = 0;+ }+ }++ $effect(() => {+ if (isDragging) {+ window.addEventListener('keydown', handleKeydown);+ return () => window.removeEventListener('keydown', handleKeydown);+ }+ });+function formatTime(date: Date | null): string {if (!date) return '';return formatDateTime(date, { timezone: tz, format: 'time' });@@ -277,12 +336,14 @@<divbind:this={containerRef}class="relative select-none w-full"- style="height: {height}px; cursor: {isInChartArea() ? 'crosshair' : 'default'};"+ style="height: {height}px; cursor: {isDragging ? 'col-resize' : (isInChartArea() ? 'crosshair' : 'default')};"onmouseenter={handleMouseEnter}onmouseleave={handleMouseLeave}onmousemove={handleMouseMove}+ onmousedown={handleMouseDown}+ onmouseup={handleMouseUp}role="application"- aria-label="Stacked area chart"+ aria-label="Stacked area chart with drag-to-zoom">{#if hasData && chartWidth > 0}<svg {width} {height}>@@ -356,8 +417,23 @@</div>{/if}+ <!-- Drag selection overlay -->+ {#if isDragging && selectionWidth > 0}+ <div+ class="absolute top-0 bottom-0 bg-primary/20 border-x border-primary/40 pointer-events-none"+ style="left: {selectionLeft}px; width: {selectionWidth}px;"+ >+ <div class="absolute -top-5 left-0 -translate-x-full text-[9px] font-medium text-primary whitespace-nowrap">+ {formatTime(selectionStartTime)}+ </div>+ <div class="absolute -top-5 right-0 translate-x-full text-[9px] font-medium text-primary whitespace-nowrap">+ {formatTime(selectionEndTime)}+ </div>+ </div>+ {/if}+<!-- Hover tooltip -->- {#if isHovering && isInChartArea() && calculatedData()}+ {#if isHovering && !isDragging && isInChartArea() && calculatedData()}{@const clampedX = Math.max(padding.left, Math.min(mouseX, width - padding.right))}{@const data = calculatedData()}@@ -380,7 +456,7 @@<div class="flex items-center gap-1.5"><span class="h-2 w-2 rounded-full flex-shrink-0" style="background-color: {getEndpointColor(endpoint)};"></span><span class="truncate max-w-[200px]" title={endpoint}>{truncateEndpoint(endpoint, 25)}</span>- <span class="ml-auto tabular-nums">{formatDisplayValue(value)}{unit ? ` ${unit}` : ''}</span>+ <span class="ml-auto tabular-nums">{formatDisplayValue(value)}{!formatValue && unit ? ` ${unit}` : ''}</span></div>{/if}{/each}diff --git a/frontend/src/lib/utils/url-params.ts b/frontend/src/lib/utils/url-params.tsindex ca8b94af..a3825ca8 100644--- a/frontend/src/lib/utils/url-params.ts+++ b/frontend/src/lib/utils/url-params.ts@@ -83,8 +83,7 @@ export function updateUrl(): void {if (!browser) return;- // Note: pushToHistory option is kept for API compatibility but we always use replaceState- // This ensures back button navigates to previous PAGE, not previous params on same page+ const { pushToHistory = false } = options;const urlParams = new URLSearchParams();for (const [key, value] of Object.entries(params)) {@@ -97,7 +96,7 @@ export function updateUrl(// eslint-disable-next-line svelte/no-navigation-without-resolvegoto(newUrl, {- replaceState: true,+ replaceState: !pushToHistory,noScroll: true,keepFocus: true});diff --git a/frontend/src/routes/endpoints/+page.svelte b/frontend/src/routes/endpoints/+page.svelteindex 137d024e..ef141f60 100644--- a/frontend/src/routes/endpoints/+page.svelte+++ b/frontend/src/routes/endpoints/+page.svelte@@ -20,6 +20,7 @@import { resolve } from '$app/paths';import PageHeader from '$lib/components/issues/page-header.svelte';import D3StackedAreaChart from '$lib/components/dashboard/d3-stacked-area-chart.svelte';+ import D3HorizontalBarChart from '$lib/components/dashboard/d3-horizontal-bar-chart.svelte';import {presetMinutes,getTimeRangeFromPreset,@@ -159,7 +160,7 @@toTime = to.time;selectedPreset = preset;page = 1;- loadData(true);+ loadData(false);}// Format count with k/m suffixes@@ -178,7 +179,7 @@const diffHours = diffMs / (1000 * 60 * 60);if (diffHours <= 1) return 1; // 1 minute- if (diffHours <= 24) return 5; // 5 minutes+ if (diffHours <= 6) return 5; // 5 minutesif (diffHours <= 24 * 7) return 60; // 1 hourreturn 240; // 4 hours}@@ -275,10 +276,53 @@loadChartData();}+ function handleChartRangeSelect(from: Date, to: Date) {+ selectedPreset = null;+ fromDate = new CalendarDate(from.getFullYear(), from.getMonth() + 1, from.getDate());+ fromTime = `${String(from.getHours()).padStart(2, '0')}:${String(from.getMinutes()).padStart(2, '0')}`;+ toDate = new CalendarDate(to.getFullYear(), to.getMonth() + 1, to.getDate());+ toTime = `${String(to.getHours()).padStart(2, '0')}:${String(to.getMinutes()).padStart(2, '0')}`;+ page = 1;+ loadData(true);+ }+const selectedMetricLabel = $derived(metricOptions.find(o => o.value === selectedMetric)?.label ?? 'Total time');- // Get the unit for the selected metric- const chartUnit = $derived(selectedMetric === 'total_time' ? 'ms' : 'ms');+ // Format total time (input is milliseconds, not nanoseconds)+ function formatTotalTime(ms: number): string {+ if (ms >= 3600000) { // >= 1 hour+ return `${(ms / 3600000).toFixed(1)}h`;+ } else if (ms >= 60000) { // >= 1 minute+ return `${(ms / 60000).toFixed(1)}m`;+ } else if (ms >= 1000) { // >= 1 second+ return `${(ms / 1000).toFixed(1)}s`;+ } else if (ms < 1) {+ return `${(ms * 1000).toFixed(0)}µs`;+ }+ return `${Math.round(ms)}ms`;+ }++ // Check if we should use bar chart (for percentile metrics)+ const useBarChart = $derived(selectedMetric !== 'total_time');++ // Get top 8 endpoints for bar chart based on selected metric+ // Sort by the selected metric to show the worst (slowest) endpoints first+ const barChartData = $derived.by(() => {+ if (!useBarChart || endpoints.length === 0) return [];++ const metricKey = selectedMetric === 'p50' ? 'p50Duration'+ : selectedMetric === 'p95' ? 'p95Duration'+ : 'p99Duration';++ return [...endpoints]+ .sort((a, b) => b[metricKey] - a[metricKey])+ .slice(0, 8)+ .map(ep => ({+ endpoint: ep.endpoint,+ value: ep[metricKey]+ }));+ });+onMount(() => {// Add popstate listener for back/forward navigation@@ -317,11 +361,11 @@<Card.Root class="pt-2"><Card.Header class="flex flex-row items-center justify-between space-y-0 border-b [.border-b]:pb-2 pl-3"><Card.Title class="text-base font-medium flex items-center gap-2">- <ChartLine class="h-3.5 w-3.5" />+ <ChartLine class="h-3.5 w-3.5 text-muted-foreground" /><DropdownMenu.Root>- <DropdownMenu.Trigger class="flex items-center text-sm gap-0.5 font-medium">+ <DropdownMenu.Trigger class="flex items-center text-sm gap-0.5 font-[400] text-muted-foreground">{selectedMetricLabel}- <ChevronDown class="h-3 w-3" />+ <ChevronDown class="h-3 w-3 text-muted-foreground" /></DropdownMenu.Trigger><DropdownMenu.Content align="start" class="w-[200px]">{#each metricOptions as option}@@ -340,15 +384,27 @@</Card.Title></Card.Header><Card.Content>- {#if chartLoading}+ {#if chartLoading && !useBarChart}<div class="flex justify-center items-center h-[220px]"><LoadingCircle size="xlg" /></div>+ {:else if useBarChart}+ {#if loading}+ <div class="flex justify-center items-center h-[220px]">+ <LoadingCircle size="xlg" />+ </div>+ {:else}+ <D3HorizontalBarChart+ data={barChartData}+ formatValue={formatDuration}+ />+ {/if}{:else}<D3StackedAreaChartendpoints={chartEndpoints}series={chartSeries}- unit={chartUnit}+ formatValue={formatTotalTime}+ onRangeSelect={handleChartRangeSelect}/>{/if}</Card.Content>