Unverified Commit 1fcdea57 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Add Request Insights filters and pause controls

Co-authored-by: 's avatarDavid Ilie <david@davidilie.com>
Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent 931dcc00
import {
getRequestInsightKind,
getRequestInsightSource,
type RequestInsight,
} from '../../../shared/request-insights'
import {
getRequestInsightRepresentation,
getRequestInsightStatusCode,
hasRequestInsightProxyActivity,
} from './request-list'
export type RequestInsightFilter =
| 'source:page'
| 'source:api'
| 'source:image'
| 'source:asset'
| 'source:unknown'
| 'representation:html'
| 'representation:rsc'
| 'representation:unknown'
| 'activity:proxy'
| 'activity:instant-insights'
| 'status:error'
| 'status:http-4xx'
| 'status:http-5xx'
| 'fetches:present'
| 'fetches:none'
| 'cache:hit'
| 'cache:miss'
| 'cache:skip'
| 'cache:none'
export type RequestInsightFilterGroup = Readonly<{
label: string
options: ReadonlyArray<{
value: RequestInsightFilter
label: string
}>
}>
export const REQUEST_INSIGHT_FILTER_GROUPS: readonly RequestInsightFilterGroup[] =
[
{
label: 'Request type',
options: [
{ value: 'source:page', label: 'Page or navigation' },
{ value: 'source:api', label: 'API' },
{ value: 'source:image', label: 'Image optimization' },
{ value: 'source:asset', label: 'Static asset' },
{ value: 'source:unknown', label: 'Unknown type' },
],
},
{
label: 'Page response',
options: [
{ value: 'representation:html', label: 'HTML' },
{ value: 'representation:rsc', label: 'RSC' },
{ value: 'representation:unknown', label: 'Unavailable' },
],
},
{
label: 'Activity',
options: [
{ value: 'activity:proxy', label: 'Matched proxy' },
{ value: 'activity:instant-insights', label: 'Instant Insights' },
],
},
{
label: 'Status',
options: [
{ value: 'status:error', label: 'Recorded error' },
{ value: 'status:http-4xx', label: 'HTTP 4xx' },
{ value: 'status:http-5xx', label: 'HTTP 5xx' },
],
},
{
label: 'Fetches',
options: [
{ value: 'fetches:present', label: 'Has fetches' },
{ value: 'fetches:none', label: 'No fetches' },
],
},
{
label: 'Fetch cache',
options: [
{ value: 'cache:hit', label: 'Hit' },
{ value: 'cache:miss', label: 'Miss' },
{ value: 'cache:skip', label: 'Skip' },
{ value: 'cache:none', label: 'No cache activity' },
],
},
]
const ALL_FILTERS = REQUEST_INSIGHT_FILTER_GROUPS.flatMap((group) =>
group.options.map((option) => option.value)
)
type RequestInsightFilterResult = Readonly<{
requests: RequestInsight[]
matchingRequestCount: number
totalRequestCount: number
optionCounts: Readonly<Record<RequestInsightFilter, number>>
}>
export function getRequestInsightFilterResult(
requests: readonly RequestInsight[],
activeFilters: readonly RequestInsightFilter[],
showInternal = false
): RequestInsightFilterResult {
const revealInternal =
showInternal || activeFilters.includes('activity:instant-insights')
const visibleRequests = requests.filter(
(request) => getRequestInsightKind(request) === 'request' || revealInternal
)
const activeFiltersByFacet = groupFiltersByFacet(activeFilters)
const optionCounts = Object.fromEntries(
ALL_FILTERS.map((filter) => [filter, 0])
) as Record<RequestInsightFilter, number>
for (const request of requests) {
const tags = getRequestInsightTags(request)
if (getRequestInsightKind(request) === 'request' || showInternal) {
for (const tag of tags) {
optionCounts[tag] += 1
}
} else if (tags.has('activity:instant-insights')) {
optionCounts['activity:instant-insights'] += 1
}
}
const matchingRequests = visibleRequests.filter((request) =>
matchesActiveFilters(getRequestInsightTags(request), activeFiltersByFacet)
)
return {
requests: matchingRequests,
matchingRequestCount: matchingRequests.length,
totalRequestCount: visibleRequests.length,
optionCounts,
}
}
export function toggleRequestInsightFilter(
activeFilters: readonly RequestInsightFilter[],
filter: RequestInsightFilter
): RequestInsightFilter[] {
return activeFilters.includes(filter)
? activeFilters.filter((activeFilter) => activeFilter !== filter)
: [...activeFilters, filter]
}
function getRequestInsightTags(
request: RequestInsight
): Set<RequestInsightFilter> {
const tags = new Set<RequestInsightFilter>()
const source = getRequestSourceFilter(request)
if (source) {
tags.add(source)
}
switch (getRequestInsightRepresentation(request)) {
case 'html':
tags.add('representation:html')
break
case 'rsc':
tags.add('representation:rsc')
break
case 'unknown':
tags.add('representation:unknown')
break
case 'not-applicable':
break
}
if (hasRequestInsightProxyActivity(request)) {
tags.add('activity:proxy')
}
if (getRequestInsightKind(request) === 'instant-insights') {
tags.add('activity:instant-insights')
}
if (
request.status === 'error' ||
request.spans.some((span) => span.status === 'error' || span.error)
) {
tags.add('status:error')
}
const statusCode = getRequestInsightStatusCode(request)
if (statusCode !== undefined && statusCode >= 400 && statusCode < 500) {
tags.add('status:http-4xx')
} else if (
statusCode !== undefined &&
statusCode >= 500 &&
statusCode < 600
) {
tags.add('status:http-5xx')
}
if (request.fetches.length === 0) {
tags.add('fetches:none')
tags.add('cache:none')
} else {
tags.add('fetches:present')
for (const fetch of request.fetches) {
if (
fetch.cacheStatus === 'hit' ||
fetch.cacheStatus === 'miss' ||
fetch.cacheStatus === 'skip'
) {
tags.add(`cache:${fetch.cacheStatus}`)
}
}
}
return tags
}
function getRequestSourceFilter(
request: RequestInsight
): RequestInsightFilter | undefined {
const source = getRequestInsightSource(request)
switch (source) {
case 'page':
return 'source:page'
case 'app-route':
case 'pages-api':
return 'source:api'
case 'image':
return 'source:image'
case 'asset':
return 'source:asset'
case 'proxy':
case 'instant-insights':
return undefined
case 'unknown':
return 'source:unknown'
}
}
function groupFiltersByFacet(
filters: readonly RequestInsightFilter[]
): Map<string, RequestInsightFilter[]> {
const filtersByFacet = new Map<string, RequestInsightFilter[]>()
for (const filter of filters) {
const facet = filter.slice(0, filter.indexOf(':'))
const facetFilters = filtersByFacet.get(facet)
if (facetFilters) {
facetFilters.push(filter)
} else {
filtersByFacet.set(facet, [filter])
}
}
return filtersByFacet
}
function matchesActiveFilters(
tags: ReadonlySet<RequestInsightFilter>,
activeFiltersByFacet: ReadonlyMap<string, RequestInsightFilter[]>
): boolean {
for (const facetFilters of activeFiltersByFacet.values()) {
if (!facetFilters.some((filter) => tags.has(filter))) {
return false
}
}
return true
}
...@@ -40,6 +40,162 @@ ...@@ -40,6 +40,162 @@
font-size: var(--size-12); font-size: var(--size-12);
} }
.request-insights-list-controls,
.request-insights-update-status {
display: flex;
min-width: 0;
align-items: center;
gap: 6px;
}
.request-insights-update-status {
color: var(--color-gray-800);
font-size: var(--size-11);
white-space: nowrap;
}
.request-insights-paused-state::before {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 4px;
border-radius: 999px;
background: var(--color-amber-800);
content: '';
}
.request-insights-filter-trigger {
display: inline-flex;
min-height: 24px;
align-items: center;
gap: 4px;
border: 1px solid var(--color-gray-400);
border-radius: 4px;
padding: 2px 6px;
background: transparent;
color: var(--color-gray-900);
cursor: pointer;
font: inherit;
}
.request-insights-filter-trigger:hover,
.request-insights-filter-trigger[aria-expanded='true'] {
background: var(--color-gray-200);
color: var(--color-gray-1000);
}
.request-insights-filter-active-count {
min-width: 16px;
border-radius: 999px;
padding: 0 4px;
background: var(--color-blue-800);
color: var(--color-background-100);
font-size: var(--size-10);
line-height: 16px;
text-align: center;
}
.request-insights-filter-positioner {
z-index: var(--top-z-index);
}
.request-insights-filter-menu {
overflow-y: auto;
overscroll-behavior-y: contain;
width: min(280px, calc(100vw - 24px));
max-height: min(560px, calc(100vh - 48px));
border: 1px solid var(--color-gray-400);
border-radius: 8px;
background: var(--color-background-100);
box-shadow: 0px 4px 8px -4px
color-mix(in srgb, var(--color-gray-900) 4%, transparent);
padding: 4px;
user-select: none;
}
.request-insights-filter-group-label {
padding: 8px 8px 3px;
color: var(--color-gray-800);
font-size: var(--size-10);
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.request-insights-filter-item {
display: grid;
grid-template-columns: 14px minmax(0, 1fr) auto;
align-items: center;
gap: 6px;
border-radius: 6px;
padding: 5px 8px;
color: var(--color-gray-1000);
cursor: pointer;
font-size: var(--size-12);
}
.request-insights-filter-item[data-highlighted] {
background: var(--color-gray-200);
}
.request-insights-filter-item[data-disabled] {
color: var(--color-gray-700);
cursor: default;
}
.request-insights-filter-option-label {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.request-insights-filter-option-count {
min-width: 20px;
color: var(--color-gray-800);
font-family: var(--font-mono);
font-size: var(--size-11);
text-align: right;
}
.request-insights-filter-reset {
display: flex;
min-height: 28px;
align-items: center;
margin-top: 4px;
border-top: 1px solid var(--color-gray-400);
padding: 6px 8px 2px;
color: var(--color-blue-900);
cursor: pointer;
font-size: var(--size-12);
}
.request-insights-filter-reset[data-disabled] {
color: var(--color-gray-700);
cursor: default;
}
.request-insights-filter-status {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 5px 10px;
border-bottom: 1px solid var(--color-gray-400);
background: var(--color-gray-100);
color: var(--color-gray-900);
font-size: var(--size-11);
}
.request-insights-filter-status button,
.request-insights-list-empty button {
border: 0;
padding: 0;
background: transparent;
color: var(--color-blue-900);
cursor: pointer;
font: inherit;
}
.request-insights-settings { .request-insights-settings {
position: relative; position: relative;
display: inline-flex; display: inline-flex;
...@@ -195,41 +351,44 @@ ...@@ -195,41 +351,44 @@
color: var(--color-gray-700); color: var(--color-gray-700);
} }
.request-insights-internal-badge { .request-insights-row-metadata {
flex-shrink: 0; display: flex;
margin-right: 6px; min-width: 0;
border: 1px solid var(--color-gray-500); overflow: hidden;
border-radius: 999px; align-items: center;
padding: 1px 6px; gap: 5px;
color: var(--color-gray-800); grid-column: 2;
font-size: var(--size-10); grid-row: 2;
font-weight: 500; text-overflow: ellipsis;
letter-spacing: 0.02em;
text-transform: uppercase;
} }
.request-insights-page-load { .request-insights-request-type,
.request-insights-request-activity {
flex-shrink: 0; flex-shrink: 0;
border-radius: 999px;
padding: 1px 5px;
background: var(--color-blue-100);
color: var(--color-blue-900);
font-size: var(--size-10);
font-weight: 600;
line-height: 16px;
white-space: nowrap;
}
.request-insights-item-context {
min-width: 0;
overflow: hidden;
color: var(--color-gray-900); color: var(--color-gray-900);
font-size: var(--size-11); font-size: var(--size-11);
font-weight: 400;
text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
.request-insights-request-type[data-type='page-load'],
.request-insights-request-type[data-type='rsc'] {
color: var(--color-blue-900);
}
.request-insights-request-type[data-type='api'] {
color: var(--color-purple-900);
}
.request-insights-request-type[data-type='image'],
.request-insights-request-type[data-type='asset'],
.request-insights-request-type[data-type='proxy'] {
color: var(--color-green-900);
}
.request-insights-request-activity {
color: var(--color-gray-800);
}
.request-insights-duration, .request-insights-duration,
.request-insights-meta { .request-insights-meta {
color: var(--color-gray-900); color: var(--color-gray-900);
......
import { import {
getRequestInsightKey, getRequestInsightKey,
getRequestInsightKind, getRequestInsightKind,
getRequestInsightSource,
REQUEST_INSIGHT_PROXY_SPAN_TYPE,
REQUEST_INSIGHT_REQUEST_SPAN_TYPE,
type RequestInsight, type RequestInsight,
type RequestInsightSpan,
} from '../../../shared/request-insights' } from '../../../shared/request-insights'
export function getActiveRequestKey( export function getActiveRequestKey(
...@@ -43,15 +47,13 @@ export function getRequestListEntries( ...@@ -43,15 +47,13 @@ export function getRequestListEntries(
.map((request) => ({ request, nested: false })) .map((request) => ({ request, nested: false }))
} }
// Group internal records by the request they belong to, and record which
// request ids have a parent (non-internal) record present, both in one pass.
const internalByRequestId = new Map<string, RequestInsight[]>() const internalByRequestId = new Map<string, RequestInsight[]>()
const parentRequestIds = new Set<string>() const parentRequestIds = new Set<string>()
for (const request of requests) { for (const request of requests) {
if (isInternalRequestInsight(request)) { if (isInternalRequestInsight(request)) {
const group = internalByRequestId.get(request.requestId) const internal = internalByRequestId.get(request.requestId)
if (group) { if (internal) {
group.push(request) internal.push(request)
} else { } else {
internalByRequestId.set(request.requestId, [request]) internalByRequestId.set(request.requestId, [request])
} }
...@@ -63,9 +65,6 @@ export function getRequestListEntries( ...@@ -63,9 +65,6 @@ export function getRequestListEntries(
const entries: RequestListEntry[] = [] const entries: RequestListEntry[] = []
for (const request of requests) { for (const request of requests) {
if (isInternalRequestInsight(request)) { if (isInternalRequestInsight(request)) {
// Orphans (no parent request in the list) remain top-level and preserve
// their ordering relative to other top-level records. Nested internal
// records are emitted under their request below.
if (!parentRequestIds.has(request.requestId)) { if (!parentRequestIds.has(request.requestId)) {
entries.push({ request, nested: false }) entries.push({ request, nested: false })
} }
...@@ -73,9 +72,9 @@ export function getRequestListEntries( ...@@ -73,9 +72,9 @@ export function getRequestListEntries(
} }
entries.push({ request, nested: false }) entries.push({ request, nested: false })
const nested = internalByRequestId.get(request.requestId) const internal = internalByRequestId.get(request.requestId)
if (nested) { if (internal) {
for (const internalRequest of nested) { for (const internalRequest of internal) {
entries.push({ request: internalRequest, nested: true }) entries.push({ request: internalRequest, nested: true })
} }
} }
...@@ -83,12 +82,220 @@ export function getRequestListEntries( ...@@ -83,12 +82,220 @@ export function getRequestListEntries(
return entries return entries
} }
export type RequestInsightRowType =
| 'page'
| 'page-load'
| 'rsc'
| 'api'
| 'image'
| 'asset'
| 'proxy'
| 'instant-insights'
| 'unknown'
export type RequestInsightRowTypePresentation = Readonly<{
type: RequestInsightRowType
label: string
accessibleLabel: string
}>
const REQUEST_INSIGHT_ROW_TYPES: Readonly<
Record<RequestInsightRowType, RequestInsightRowTypePresentation>
> = {
page: { type: 'page', label: 'Page', accessibleLabel: 'Page request' },
'page-load': {
type: 'page-load',
label: 'Page load',
accessibleLabel: 'Page load',
},
rsc: {
type: 'rsc',
label: 'RSC',
accessibleLabel: 'React Server Component request',
},
api: { type: 'api', label: 'API', accessibleLabel: 'API request' },
image: {
type: 'image',
label: 'Image',
accessibleLabel: 'Image optimization request',
},
asset: {
type: 'asset',
label: 'Asset',
accessibleLabel: 'Static asset request',
},
proxy: { type: 'proxy', label: 'Proxy', accessibleLabel: 'Proxy request' },
'instant-insights': {
type: 'instant-insights',
label: 'Instant',
accessibleLabel: 'Instant Insights activity',
},
unknown: {
type: 'unknown',
label: 'Unknown',
accessibleLabel: 'Unclassified request',
},
}
export function getRequestInsightRowType(
request: RequestInsight,
pageLoad = false
): RequestInsightRowTypePresentation {
switch (getRequestInsightSource(request)) {
case 'page': {
if (getRequestInsightIsRsc(request) === true) {
return REQUEST_INSIGHT_ROW_TYPES.rsc
}
return REQUEST_INSIGHT_ROW_TYPES[pageLoad ? 'page-load' : 'page']
}
case 'app-route':
case 'pages-api':
return REQUEST_INSIGHT_ROW_TYPES.api
case 'image':
return REQUEST_INSIGHT_ROW_TYPES.image
case 'asset':
return REQUEST_INSIGHT_ROW_TYPES.asset
case 'proxy':
return REQUEST_INSIGHT_ROW_TYPES.proxy
case 'instant-insights':
return REQUEST_INSIGHT_ROW_TYPES['instant-insights']
case 'unknown':
return REQUEST_INSIGHT_ROW_TYPES.unknown
}
}
export function hasRequestInsightProxyActivity(
request: RequestInsight
): boolean {
return (
getRequestInsightSource(request) === 'proxy' ||
request.proxyStatus === 'matched' ||
request.spans.some(
(span) =>
span.attributes?.['next.span_type'] === REQUEST_INSIGHT_PROXY_SPAN_TYPE
)
)
}
export function getCanonicalRequestSpan(
request: Pick<RequestInsight, 'route' | 'spans'>
): RequestInsightSpan | undefined {
let latestRequestSpan: RequestInsightSpan | undefined
let latestMatchedRouteSpan: RequestInsightSpan | undefined
for (const span of request.spans) {
if (
span.attributes?.['next.span_type'] !== REQUEST_INSIGHT_REQUEST_SPAN_TYPE
) {
continue
}
if (!latestRequestSpan || span.startTime >= latestRequestSpan.startTime) {
latestRequestSpan = span
}
if (
request.route &&
span.attributes?.['next.route'] === request.route &&
(!latestMatchedRouteSpan ||
span.startTime >= latestMatchedRouteSpan.startTime)
) {
latestMatchedRouteSpan = span
}
}
return latestMatchedRouteSpan ?? latestRequestSpan
}
export function getRequestInsightStatusCode(
request: Pick<RequestInsight, 'route' | 'spans'>
): number | undefined {
return getCanonicalThenAnySpanAttribute(
request,
'http.status_code',
(value): value is number => typeof value === 'number'
)
}
export function getRequestInsightIsRsc(
request: Pick<RequestInsight, 'route' | 'spans'>
): boolean | undefined {
return getCanonicalThenAnySpanAttribute(
request,
'next.rsc',
(value): value is boolean => typeof value === 'boolean'
)
}
export type RequestInsightRepresentation =
| 'html'
| 'rsc'
| 'not-applicable'
| 'unknown'
export function getRequestInsightRepresentation(
request: Pick<RequestInsight, 'kind' | 'source' | 'route' | 'spans'>
): RequestInsightRepresentation {
switch (getRequestInsightSource(request)) {
case 'page': {
const isRsc = getRequestInsightIsRsc(request)
return isRsc === true ? 'rsc' : isRsc === false ? 'html' : 'unknown'
}
case 'unknown':
return 'unknown'
case 'app-route':
case 'pages-api':
case 'image':
case 'asset':
case 'proxy':
case 'instant-insights':
return 'not-applicable'
}
}
export function getRequestInsightSummaryTypeLabel(
request: RequestInsight
): string {
const rowType = getRequestInsightRowType(request)
if (rowType.type === 'instant-insights') {
return rowType.accessibleLabel
}
switch (getRequestInsightRepresentation(request)) {
case 'html':
return 'HTML request'
case 'rsc':
return 'RSC request'
case 'not-applicable':
case 'unknown':
return rowType.accessibleLabel
}
}
function getCanonicalThenAnySpanAttribute<T>(
request: Pick<RequestInsight, 'route' | 'spans'>,
key: string,
isValue: (value: unknown) => value is T
): T | undefined {
const canonicalValue = getCanonicalRequestSpan(request)?.attributes?.[key]
if (isValue(canonicalValue)) {
return canonicalValue
}
for (const span of request.spans) {
const value = span.attributes?.[key]
if (isValue(value)) {
return value
}
}
}
export function isPageLoadRequest( export function isPageLoadRequest(
request: Pick<RequestInsight, 'requestId' | 'kind'>, request: RequestInsight,
initialRequestId: string | undefined initialRequestId: string | undefined
): boolean { ): boolean {
return ( return (
getRequestInsightKind(request) === 'request' && getRequestInsightKind(request) === 'request' &&
request.requestId === initialRequestId getRequestInsightSource(request) === 'page' &&
getRequestInsightIsRsc(request) === false &&
request.htmlRequestId === initialRequestId
) )
} }
import type { RequestInsight } from '../../../shared/request-insights' import {
REQUEST_INSIGHT_REQUEST_SPAN_TYPE,
type RequestInsight,
} from '../../../shared/request-insights'
import { getRequestInsightFilterResult } from './request-filters'
import { import {
getActiveRequestKey, getActiveRequestKey,
getRequestInsightRowType,
getRequestListEntries, getRequestListEntries,
isPageLoadRequest, isPageLoadRequest,
} from './request-list' } from './request-list'
...@@ -62,7 +67,7 @@ describe('request insights trace viewer', () => { ...@@ -62,7 +67,7 @@ describe('request insights trace viewer', () => {
]) ])
}) })
it('nests internal records directly after their request row', () => { it('nests internal records under their owning request', () => {
const newerRequest = createRequest({ requestId: 'newer' }) const newerRequest = createRequest({ requestId: 'newer' })
const olderRequest = createRequest({ requestId: 'older' }) const olderRequest = createRequest({ requestId: 'older' })
const newerInstantInsights = createRequest({ const newerInstantInsights = createRequest({
...@@ -92,42 +97,82 @@ describe('request insights trace viewer', () => { ...@@ -92,42 +97,82 @@ describe('request insights trace viewer', () => {
]) ])
}) })
it('keeps orphaned internal records top-level and in root ordering', () => { it('keeps internal records without a retained owner at the root', () => {
const request = createRequest({ requestId: 'present' }) const instantInsights = createRequest({
const presentInstantInsights = createRequest({ requestId: 'orphan',
requestId: 'present',
kind: 'instant-insights',
})
const orphanInstantInsights = createRequest({
requestId: 'evicted',
kind: 'instant-insights', kind: 'instant-insights',
}) })
const entries = getRequestListEntries( expect(getRequestListEntries([instantInsights], true)).toEqual([
[presentInstantInsights, orphanInstantInsights, request], { request: instantInsights, nested: false },
true
)
expect(entries).toEqual([
{ request: orphanInstantInsights, nested: false },
{ request, nested: false },
{ request: presentInstantInsights, nested: true },
]) ])
// Every record appears exactly once. })
expect(new Set(entries.map((entry) => entry.request)).size).toBe(
entries.length it('labels and filters normalized request activity', () => {
) const requestSpan = (rsc: boolean) => ({
expect(entries).toHaveLength(3) name: 'GET',
startTime: 100,
attributes: {
'next.span_type': REQUEST_INSIGHT_REQUEST_SPAN_TYPE,
'next.rsc': rsc,
},
})
const page = createRequest({
requestId: 'page',
source: 'page',
spans: [requestSpan(false)],
fetches: [{ cacheStatus: 'miss' }],
})
const rsc = createRequest({
requestId: 'rsc',
source: 'page',
spans: [requestSpan(true)],
})
const api = createRequest({ requestId: 'api', source: 'app-route' })
const asset = createRequest({ requestId: 'asset', source: 'asset' })
expect(getRequestInsightRowType(page, true).label).toBe('Page load')
expect(getRequestInsightRowType(rsc).label).toBe('RSC')
expect(getRequestInsightRowType(api).label).toBe('API')
expect(getRequestInsightRowType(asset).label).toBe('Asset')
expect(
getRequestInsightFilterResult(
[page, rsc, api],
['source:page', 'cache:miss']
).requests
).toEqual([page])
expect(
getRequestInsightFilterResult([page, rsc, api, asset], ['source:api'])
.requests
).toEqual([api])
expect(
getRequestInsightFilterResult([page, rsc, api, asset], ['source:asset'])
.requests
).toEqual([asset])
}) })
it('only marks the exact initial document request as the page load', () => { it('only marks the exact initial document request as the page load', () => {
const initialRequestId = 'document-request' const initialRequestId = 'document-request'
const htmlSpan = {
name: 'GET',
startTime: 100,
attributes: {
'next.span_type': REQUEST_INSIGHT_REQUEST_SPAN_TYPE,
'next.rsc': false,
},
}
const rscSpan = {
...htmlSpan,
attributes: { ...htmlSpan.attributes, 'next.rsc': true },
}
expect( expect(
isPageLoadRequest( isPageLoadRequest(
createRequest({ createRequest({
requestId: initialRequestId, requestId: 'server-owned-request',
source: 'page',
htmlRequestId: initialRequestId, htmlRequestId: initialRequestId,
spans: [htmlSpan],
}), }),
initialRequestId initialRequestId
) )
...@@ -136,7 +181,9 @@ describe('request insights trace viewer', () => { ...@@ -136,7 +181,9 @@ describe('request insights trace viewer', () => {
isPageLoadRequest( isPageLoadRequest(
createRequest({ createRequest({
requestId: 'related-rsc-request', requestId: 'related-rsc-request',
source: 'page',
htmlRequestId: initialRequestId, htmlRequestId: initialRequestId,
spans: [rscSpan],
}), }),
initialRequestId initialRequestId
) )
...@@ -145,7 +192,9 @@ describe('request insights trace viewer', () => { ...@@ -145,7 +192,9 @@ describe('request insights trace viewer', () => {
isPageLoadRequest( isPageLoadRequest(
createRequest({ createRequest({
requestId: initialRequestId, requestId: initialRequestId,
source: 'instant-insights',
kind: 'instant-insights', kind: 'instant-insights',
spans: [htmlSpan],
}), }),
initialRequestId initialRequestId
) )
......
...@@ -8,6 +8,8 @@ export { ...@@ -8,6 +8,8 @@ export {
getRequestInsightKey, getRequestInsightKey,
getRequestInsightKind, getRequestInsightKind,
getRequestInsightSource, getRequestInsightSource,
REQUEST_INSIGHT_PROXY_SPAN_TYPE,
REQUEST_INSIGHT_REQUEST_SPAN_TYPE,
type RequestInsightIdentity, type RequestInsightIdentity,
type RequestInsightKind, type RequestInsightKind,
type RequestInsightProxyStatus, type RequestInsightProxyStatus,
......
...@@ -409,6 +409,7 @@ describe('request insights', () => { ...@@ -409,6 +409,7 @@ describe('request insights', () => {
function getSettingsMenuState(): Promise<{ function getSettingsMenuState(): Promise<{
open: boolean open: boolean
checked: string | null checked: string | null
diagnosisVisible: boolean
}> { }> {
return browser.eval(() => { return browser.eval(() => {
const root = document.querySelector('nextjs-portal')?.shadowRoot const root = document.querySelector('nextjs-portal')?.shadowRoot
...@@ -421,6 +422,9 @@ describe('request insights', () => { ...@@ -421,6 +422,9 @@ describe('request insights', () => {
item item
?.querySelector('.request-insights-settings-checkbox') ?.querySelector('.request-insights-settings-checkbox')
?.getAttribute('data-checked') ?? null, ?.getAttribute('data-checked') ?? null,
diagnosisVisible: Boolean(
root?.querySelector('.request-insights-diagnosis')
),
} }
}) })
} }
...@@ -453,6 +457,7 @@ describe('request insights', () => { ...@@ -453,6 +457,7 @@ describe('request insights', () => {
expect(await getSettingsMenuState()).toEqual({ expect(await getSettingsMenuState()).toEqual({
open: true, open: true,
checked: null, checked: null,
diagnosisVisible: false,
}) })
}) })
...@@ -472,6 +477,7 @@ describe('request insights', () => { ...@@ -472,6 +477,7 @@ describe('request insights', () => {
expect(await getSettingsMenuState()).toEqual({ expect(await getSettingsMenuState()).toEqual({
open: true, open: true,
checked: 'true', checked: 'true',
diagnosisVisible: true,
}) })
expect(await getSpanRowCount()).toBeGreaterThan(defaultSpanRowCount) expect(await getSpanRowCount()).toBeGreaterThan(defaultSpanRowCount)
}) })
...@@ -496,6 +502,7 @@ describe('request insights', () => { ...@@ -496,6 +502,7 @@ describe('request insights', () => {
expect(await getSettingsMenuState()).toEqual({ expect(await getSettingsMenuState()).toEqual({
open: true, open: true,
checked: 'true', checked: 'true',
diagnosisVisible: true,
}) })
}) })
}) })
...@@ -544,6 +551,7 @@ describe('request insights', () => { ...@@ -544,6 +551,7 @@ describe('request insights', () => {
await browser.elementByCss('.request-insights-settings-trigger').click() await browser.elementByCss('.request-insights-settings-trigger').click()
await retry(async () => { await retry(async () => {
expect(await getSettingsMenuItems()).toEqual([ expect(await getSettingsMenuItems()).toEqual([
{ label: 'Pause updates', checked: null },
{ label: 'Internal activity', checked: null }, { label: 'Internal activity', checked: null },
{ label: 'Verbose traces', checked: null }, { label: 'Verbose traces', checked: null },
]) ])
...@@ -561,26 +569,26 @@ describe('request insights', () => { ...@@ -561,26 +569,26 @@ describe('request insights', () => {
.click() .click()
await retry(async () => { await retry(async () => {
const nestedRows = await browser.eval(() => { const internalRows = await browser.eval(() => {
const root = document.querySelector('nextjs-portal')?.shadowRoot const root = document.querySelector('nextjs-portal')?.shadowRoot
return Array.from( return Array.from(
root?.querySelectorAll('.request-insights-row[data-nested="true"]') ?? root?.querySelectorAll(
[] '.request-insights-row[data-internal="true"]'
) ?? []
).map((row) => ({ ).map((row) => ({
internal: row.getAttribute('data-internal'), nested: row.hasAttribute('data-nested'),
hasArrow: !!row.querySelector('.request-insights-nested-arrow'),
label: row.textContent ?? '', label: row.textContent ?? '',
})) }))
}) })
expect(await getSettingsMenuItems()).toEqual([ expect(await getSettingsMenuItems()).toEqual([
{ label: 'Pause updates', checked: null },
{ label: 'Internal activity', checked: 'true' }, { label: 'Internal activity', checked: 'true' },
{ label: 'Verbose traces', checked: 'true' }, { label: 'Verbose traces', checked: 'true' },
]) ])
expect(nestedRows.length).toBeGreaterThan(0) expect(internalRows.length).toBeGreaterThan(0)
for (const row of nestedRows) { expect(internalRows.some((row) => row.nested)).toBe(true)
expect(row.internal).toBe('true') for (const row of internalRows) {
expect(row.hasArrow).toBe(true)
expect(row.label).toContain('Instant Insights') expect(row.label).toContain('Instant Insights')
} }
}) })
...@@ -602,12 +610,125 @@ describe('request insights', () => { ...@@ -602,12 +610,125 @@ describe('request insights', () => {
await retry(async () => { await retry(async () => {
expect(await getSettingsMenuItems()).toEqual([ expect(await getSettingsMenuItems()).toEqual([
{ label: 'Pause updates', checked: null },
{ label: 'Internal activity', checked: 'true' }, { label: 'Internal activity', checked: 'true' },
{ label: 'Verbose traces', checked: 'true' }, { label: 'Verbose traces', checked: 'true' },
]) ])
}) })
}) })
it('enables internal activity when filtering Instant Insights', async () => {
const browser = await next.browser('/instant-insights')
shouldResetRequestInsightsConfig = true
await openRequestInsightsPanel(browser)
await browser.elementByCss('.request-insights-filter-trigger').click()
await browser
.elementByCss(
'.request-insights-filter-item[data-filter-value="activity:instant-insights"]'
)
.click()
await retry(async () => {
const internalRowCount = await browser.eval(() => {
const root = document.querySelector('nextjs-portal')?.shadowRoot
return (
root?.querySelectorAll('.request-insights-row[data-internal="true"]')
.length ?? 0
)
})
const config = JSON.parse(
await next.readFile('build/dev/cache/next-devtools-config.json')
)
expect(internalRowCount).toBeGreaterThan(0)
expect(config.requestInsights?.showInternal).toBe(true)
})
await browser.elementByCss('.request-insights-details').click()
await browser.elementByCss('.request-insights-settings-trigger').click()
await retry(async () => {
const checked = await browser.eval(() => {
const root = document.querySelector('nextjs-portal')?.shadowRoot
const item = Array.from(
root?.querySelectorAll('.request-insights-settings-item') ?? []
).find((element) => element.textContent?.includes('Internal activity'))
return item
?.querySelector('.request-insights-settings-checkbox')
?.getAttribute('data-checked')
})
expect(checked).toBe('true')
})
})
it('filters typed request rows and pauses live updates', async () => {
const browser = await next.browser('/instant-insights')
expect((await next.fetch('/api/source?before=pause')).status).toBe(200)
await openRequestInsightsPanel(browser)
await browser.elementByCss('.request-insights-filter-trigger').click()
await browser
.elementByCss(
'.request-insights-filter-item[data-filter-value="source:api"]'
)
.click()
await retry(async () => {
const rowTypes = await browser.eval(() => {
const root = document.querySelector('nextjs-portal')?.shadowRoot
return Array.from(
root?.querySelectorAll('.request-insights-request-type') ?? []
).map((type) => type.textContent?.trim())
})
expect(rowTypes.length).toBeGreaterThan(0)
expect(new Set(rowTypes)).toEqual(new Set(['API']))
})
await browser.elementByCss('.request-insights-details').click()
await browser.elementByCss('.request-insights-settings-trigger').click()
await browser
.elementByCss('.request-insights-settings-item:has-text("Pause updates")')
.click()
const pausedRowCount = await browser.eval(() => {
const root = document.querySelector('nextjs-portal')?.shadowRoot
return root?.querySelectorAll('.request-insights-row').length ?? 0
})
expect((await next.fetch('/api/source?while=paused')).status).toBe(200)
await retry(async () => {
const pausedState = await browser.eval(() => {
const root = document.querySelector('nextjs-portal')?.shadowRoot
return {
paused: root?.querySelector('.request-insights-paused-state')
?.textContent,
rowCount: root?.querySelectorAll('.request-insights-row').length ?? 0,
}
})
expect(pausedState).toEqual({
paused: 'Paused',
rowCount: pausedRowCount,
})
})
await browser
.elementByCss('.request-insights-settings-item:has-text("Pause updates")')
.click()
await retry(async () => {
const state = await browser.eval(() => {
const root = document.querySelector('nextjs-portal')?.shadowRoot
return {
paused: root?.querySelector('.request-insights-paused-state'),
rowCount: root?.querySelectorAll('.request-insights-row').length ?? 0,
}
})
expect(state.paused).toBeNull()
expect(state.rowCount).toBeGreaterThan(pausedRowCount)
})
})
it('classifies an App Route before its handler completes', async () => { it('classifies an App Route before its handler completes', async () => {
const waitKey = `active-${Date.now()}` const waitKey = `active-${Date.now()}`
const requestPath = `/api/app-stream-lifecycle?wait=${waitKey}` const requestPath = `/api/app-stream-lifecycle?wait=${waitKey}`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment