Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(frontend): add connection timing to app boot timing (#123222)

Paul D'Ambra531a053f2408
diff --git a/frontend/src/lib/utils/bootTiming.test.ts b/frontend/src/lib/utils/bootTiming.test.ts
index eae4d1fc2e4f..674ad2c84046 100644
--- a/frontend/src/lib/utils/bootTiming.test.ts
+++ b/frontend/src/lib/utils/bootTiming.test.ts
@@ -155,14 +155,58 @@ describe('bootTiming', () => {
it.each([
{
name: 'splits the entry phase with navigation timing',
- navigationEntries: [{ type: 'navigate', requestStart: 120.4, responseStart: 310.6, responseEnd: 352.2 }],
+ navigationEntries: [
+ {
+ type: 'navigate',
+ nextHopProtocol: 'h2',
+ domainLookupStart: 2,
+ domainLookupEnd: 30.4,
+ connectStart: 30.4,
+ secureConnectionStart: 80.2,
+ connectEnd: 119.6,
+ requestStart: 120.4,
+ responseStart: 310.6,
+ responseEnd: 352.2,
+ },
+ ],
expected: {
navigation_type: 'navigate',
+ next_hop_protocol: 'h2',
+ dns_ms: 28,
+ connect_ms: 89,
+ tls_ms: 39,
request_start_ms: 120,
response_start_ms: 311,
response_end_ms: 352,
},
},
+ {
+ name: 'reports no connection or TLS time on a reused connection',
+ navigationEntries: [
+ {
+ type: 'reload',
+ nextHopProtocol: 'h2',
+ domainLookupStart: 5,
+ domainLookupEnd: 5,
+ connectStart: 5,
+ secureConnectionStart: 5,
+ connectEnd: 5,
+ requestStart: 6,
+ responseStart: 150,
+ responseEnd: 160,
+ },
+ ],
+ expected: {
+ navigation_type: 'reload',
+ next_hop_protocol: 'h2',
+ dns_ms: 0,
+ connect_ms: null,
+ tls_ms: null,
+ request_start_ms: 6,
+ response_start_ms: 150,
+ response_end_ms: 160,
+ },
+ },
{
name: 'still sends the event without a navigation entry',
navigationEntries: [],
@@ -189,8 +233,18 @@ describe('bootTiming', () => {
Reflect.deleteProperty(performance, 'getEntriesByType')
}
- const { navigation_type, request_start_ms, response_start_ms, response_end_ms } = capture.mock.calls[0][1]
- expect({ navigation_type, request_start_ms, response_start_ms, response_end_ms }).toEqual(expected)
+ const navigationKeys = [
+ 'navigation_type',
+ 'next_hop_protocol',
+ 'dns_ms',
+ 'connect_ms',
+ 'tls_ms',
+ 'request_start_ms',
+ 'response_start_ms',
+ 'response_end_ms',
+ ]
+ const properties = capture.mock.calls[0][1]
+ expect(Object.fromEntries(navigationKeys.map((key) => [key, properties[key]]))).toEqual(expected)
})
it('reports a page hidden only between two marks', async () => {
diff --git a/frontend/src/lib/utils/bootTiming.ts b/frontend/src/lib/utils/bootTiming.ts
index 48da2fb3f9d2..e964742bc3f8 100644
--- a/frontend/src/lib/utils/bootTiming.ts
+++ b/frontend/src/lib/utils/bootTiming.ts
@@ -27,8 +27,14 @@ function getNavigationProperties(): Record<string, string | number | null> {
if (!navigation) {
return { navigation_type: null }
}
+ const openedNewConnection = navigation.connectEnd > navigation.connectStart
+ const didTlsHandshake = openedNewConnection && navigation.secureConnectionStart > 0
return {
navigation_type: navigation.type,
+ next_hop_protocol: navigation.nextHopProtocol || null,
+ dns_ms: Math.round(navigation.domainLookupEnd - navigation.domainLookupStart),
+ connect_ms: openedNewConnection ? Math.round(navigation.connectEnd - navigation.connectStart) : null,
+ tls_ms: didTlsHandshake ? Math.round(navigation.connectEnd - navigation.secureConnectionStart) : null,
request_start_ms: Math.round(navigation.requestStart),
response_start_ms: Math.round(navigation.responseStart),
response_end_ms: Math.round(navigation.responseEnd),