The only tool you need to know what is happening and how to fix it.
Go alertingexception-trackerissue-trackinglogsmetricsmonitoringobservability-platformopen-telemetryotelsession-replaytelemetrytraces
<script lang="ts">
import { untrack } from 'svelte';
import { goto } from '$app/navigation';
import { api } from '$lib/api';
import { formatDuration, getStatusColor, formatDateTime } from '$lib/utils/formatters';
import { getTimezone } from '$lib/state/timezone.svelte';
import { Button } from '$lib/components/ui/button';
import * as Card from '$lib/components/ui/card';
import * as Table from '$lib/components/ui/table';
import { LoadingCircle } from '$lib/components/ui/loading-circle';
import { ErrorDisplay } from '$lib/components/ui/error-display';
import { projectsState } from '$lib/state/projects.svelte';
import { ArrowRight, TriangleAlert, ClipboardList } from '@lucide/svelte';
import { LabelValue } from '$lib/components/ui/label-value';
import { AttributesGrid } from '$lib/components/ui/attributes-grid/index.js';
import SpanWaterfall from '$lib/components/spans/span-waterfall.svelte';
import SpanGraphNotice from '$lib/components/spans/span-graph-notice.svelte';
import SpanEmptyState from '$lib/components/spans/span-empty-state.svelte';
import type { TraceDetailResponse } from '$lib/types/spans';
import PageHeader from '$lib/components/traceway/page-header.svelte';
import TableContainer from '$lib/components/traceway/table-container.svelte';
import { createRowClickHandler } from '$lib/utils/navigation';
import { createSmartBackHandler } from '$lib/utils/back-navigation';
import { resolve } from '$app/paths';
import DistributedTraceCard from '$lib/components/distributed-trace/distributed-trace-card.svelte';
import TraceLogsPanel from '$lib/components/trace-logs/trace-logs-panel.svelte';
let { data } = $props();
const timezone = $derived(getTimezone());
// Raw on purpose: the response can carry 20,000 spans and is only ever replaced, never edited.
let response = $state.raw<TraceDetailResponse | null>(null);
let loading = $state(true);
let error = $state('');
let notFound = $state(false);
let loadSequence = 0;
async function loadData() {
const sequence = ++loadSequence;
loading = true;
error = '';
notFound = false;
try {
const result = await api.post(
`/endpoints/${data.endpointId}`,
data.recordedAt ? { recordedAt: data.recordedAt } : {},
{ projectId: projectsState.currentProjectId ?? undefined }
);
if (sequence !== loadSequence) return;
response = result;
} catch (e: unknown) {
if (sequence !== loadSequence) return;
console.error(e);
const err = e as { status?: number; message?: string };
if (err.status === 404) {
notFound = true;
} else {
error = err.message || 'Failed to load endpoint details';
}
} finally {
if (sequence === loadSequence) loading = false;
}
}
function formatBytes(bytes: number): string {
if (bytes < 1024) {
return `${bytes} B`;
} else if (bytes < 1024 * 1024) {
return `${(bytes / 1024).toFixed(1)} KB`;
} else {
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
}
}
$effect(() => {
void data.endpointId;
void data.recordedAt;
void projectsState.currentProjectId;
untrack(() => {
response = null;
loadData();
});
return () => {
loadSequence++;
};
});
</script>
<div class="space-y-6">
<PageHeader
title={decodeURIComponent(data.endpoint)}
subtitle={`Endpoint ID: ${data.endpointId}`}
onBack={createSmartBackHandler({
fallbackPath: resolve('/endpoints/[endpoint]', {
endpoint: encodeURIComponent(data.endpoint)
})
})}
/>
{#if loading}
<div class="flex items-center justify-center py-20">
<LoadingCircle size="xlg" />
</div>
{:else if notFound}
<ErrorDisplay
status={404}
title="Endpoint Not Found"
description="The endpoint instance you're looking for doesn't exist or may have expired."
onBack={createSmartBackHandler({
fallbackPath: resolve('/endpoints/[endpoint]', {
endpoint: encodeURIComponent(data.endpoint)
})
})}
backLabel="Back to Endpoint"
onRetry={loadData}
identifier={data.endpointId}
/>
{:else if error}
<ErrorDisplay
status={400}
title="Failed to Load Endpoint"
description={error}
onBack={createSmartBackHandler({
fallbackPath: resolve('/endpoints/[endpoint]', {
endpoint: encodeURIComponent(data.endpoint)
})
})}
backLabel="Back to Endpoint"
onRetry={loadData}
/>
{:else if response}
<!-- Endpoint Details Card -->
<Card.Root>
<Card.Header>
<Card.Title>Endpoint Details</Card.Title>
<Card.Description>Details of this specific endpoint occurrence</Card.Description>
</Card.Header>
<Card.Content class="space-y-6">
<div class="grid grid-cols-2 gap-4 md:grid-cols-4">
<LabelValue label="Endpoint" value={decodeURIComponent(data.endpoint)} mono />
<LabelValue
label="Status"
value={response.endpoint.statusCode}
mono
large
valueClass={getStatusColor(response.endpoint.statusCode)}
/>
<LabelValue
label="Duration"
value={formatDuration(response.endpoint.duration)}
mono
large
/>
<LabelValue
label="Recorded At"
value={formatDateTime(response.endpoint.recordedAt, { timezone })}
mono
/>
<LabelValue label="Server" value={response.endpoint.serverName} mono />
<LabelValue label="Version" value={response.endpoint.appVersion || '-'} mono />
<LabelValue label="Client IP" value={response.endpoint.clientIP} mono />
<LabelValue label="Body Size" value={formatBytes(response.endpoint.bodySize)} mono />
</div>
{#if response.endpoint.attributes && Object.keys(response.endpoint.attributes).length > 0}
<hr class="border-border" />
<div>
<p class="mb-3 text-sm font-medium">Attributes</p>
<AttributesGrid attributes={response.endpoint.attributes} />
</div>
{/if}
</Card.Content>
</Card.Root>
<!-- Exception Card (if exception exists) -->
{#if response.exception}
<Card.Root class="border-red-500/30 bg-red-500/5">
<Card.Header>
<div class="flex items-center gap-2">
<TriangleAlert class="h-5 w-5 text-red-500" />
<Card.Title class="text-red-600 dark:text-red-400">Exception Occurred</Card.Title>
</div>
<Card.Description>This endpoint request resulted in an exception</Card.Description>
</Card.Header>
<Card.Content>
<div class="mb-4 max-h-32 overflow-x-auto rounded-md bg-muted p-3">
<pre class="font-mono text-sm whitespace-pre-wrap">{response.exception.stackTrace
.split('\n')
.slice(0, 4)
.join('\n')}{response.exception.stackTrace.split('\n').length > 4
? '\n...'
: ''}</pre>
</div>
<Button
variant="outline"
size="sm"
onclick={() => goto(resolve(`/issues/${response!.exception!.exceptionHash}`))}
>
View Full Exception
<ArrowRight class="ml-2 h-4 w-4" />
</Button>
</Card.Content>
</Card.Root>
{/if}
<!-- Messages Section (if messages exist) -->
{#if response.messages.length > 0}
<Card.Root>
<Card.Header>
<div class="flex items-center gap-2">
<ClipboardList class="h-5 w-5 text-muted-foreground" />
<Card.Title>Messages</Card.Title>
</div>
<Card.Description>
{response.messages.length} message{response.messages.length === 1 ? '' : 's'} logged during
this request
</Card.Description>
</Card.Header>
<Card.Content class="px-0 pb-0">
<TableContainer class="rounded-none border-0">
<Table.Root>
<Table.Header>
<Table.Row>
<Table.Head class="pl-6">Message</Table.Head>
<Table.Head class="w-[180px]">Recorded At</Table.Head>
<Table.Head class="w-[100px] pr-6">Attributes</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{#each response.messages as message, __index (__index)}
<Table.Row
class="cursor-pointer"
onclick={createRowClickHandler(
`/issues/${message.exceptionHash}/${message.id}`
)}
>
<Table.Cell class="pl-6">
<div class="max-w-md truncate font-mono text-sm">
{message.stackTrace.split('\n')[0]}
</div>
</Table.Cell>
<Table.Cell class="font-mono text-sm text-muted-foreground">
{formatDateTime(message.recordedAt, { timezone })}
</Table.Cell>
<Table.Cell class="pr-6">
{#if message.attributes && Object.keys(message.attributes).length > 0}
<span class="text-xs text-muted-foreground">
{Object.keys(message.attributes).length} key{Object.keys(
message.attributes
).length === 1
? ''
: 's'}
</span>
{:else}
<span class="text-xs text-muted-foreground">-</span>
{/if}
</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
</TableContainer>
</Card.Content>
</Card.Root>
{/if}
<!-- Spans Section -->
<Card.Root>
{#if response.hasSpans}
<Card.Header>
<Card.Title>Spans</Card.Title>
<Card.Description>
Timing breakdown of operations within this endpoint request
</Card.Description>
</Card.Header>
{/if}
<Card.Content class="space-y-3">
<SpanGraphNotice status={response.spanGraphStatus} />
{#if response.hasSpans}
<SpanWaterfall
spans={response.spans}
traceDuration={response.endpoint.duration}
traceStartTime={response.endpoint.recordedAt}
traceId={response.endpoint.traceId}
rootSpanId={response.endpoint.spanId}
/>
{:else if !response.spanGraphStatus || response.spanGraphStatus.state === 'complete'}
<SpanEmptyState framework={projectsState.currentProject?.framework ?? 'gin'} />
{/if}
</Card.Content>
</Card.Root>
<TraceLogsPanel
projectId={projectsState.currentProjectId ?? ''}
traceId={response.endpoint.traceId}
spans={response.spans ?? []}
rootSpan={{ spanId: response.endpoint.spanId, name: response.endpoint.endpoint }}
traceRecordedAt={response.endpoint.recordedAt}
/>
{#if response.endpoint.traceId}
<DistributedTraceCard
traceId={response.endpoint.traceId}
currentNodeId={response.endpoint.id}
recordedAt={response.endpoint.recordedAt}
/>
{/if}
{/if}
</div>