2021-05-21 07:32:07 -04:00
|
|
|
import { v4 as uuid } from 'uuid'
|
2021-06-01 09:53:27 -04:00
|
|
|
import { sendMB } from '../../../infrastructure/event-tracking'
|
2022-07-20 04:32:05 -04:00
|
|
|
import { trackPdfDownloadEnabled } from './pdf-caching-flags'
|
2023-09-27 05:45:49 -04:00
|
|
|
import { debugConsole } from '@/utils/debugging'
|
2021-05-21 07:32:07 -04:00
|
|
|
|
2021-06-14 04:44:25 -04:00
|
|
|
// VERSION should get incremented when making changes to caching behavior or
|
|
|
|
// adjusting metrics collection.
|
2022-11-09 04:22:31 -05:00
|
|
|
const VERSION = 9
|
2021-06-14 04:44:25 -04:00
|
|
|
|
2022-07-08 04:15:13 -04:00
|
|
|
// editing session id
|
|
|
|
const EDITOR_SESSION_ID = uuid()
|
2021-05-21 07:32:07 -04:00
|
|
|
|
2022-07-20 04:15:41 -04:00
|
|
|
const pdfCachingMetrics = {
|
|
|
|
viewerId: EDITOR_SESSION_ID,
|
|
|
|
}
|
2022-07-06 07:06:53 -04:00
|
|
|
|
2022-07-20 04:15:41 -04:00
|
|
|
export function getPdfCachingMetrics() {
|
|
|
|
return pdfCachingMetrics
|
2022-07-06 07:06:53 -04:00
|
|
|
}
|
|
|
|
|
2022-07-18 06:24:31 -04:00
|
|
|
export function trackPdfDownload(response, compileTimeClientE2E, t0) {
|
2022-10-25 05:24:11 -04:00
|
|
|
const { timings, pdfCachingMinChunkSize } = response
|
2021-05-21 07:32:07 -04:00
|
|
|
|
2022-06-21 08:15:26 -04:00
|
|
|
const deliveryLatencies = {
|
|
|
|
compileTimeClientE2E,
|
|
|
|
compileTimeServerE2E: timings?.compileE2E,
|
|
|
|
}
|
|
|
|
|
2022-07-18 06:24:31 -04:00
|
|
|
// There can be multiple "first" renderings with two pdf viewers.
|
|
|
|
// E.g. two pdf detach tabs or pdf detacher plus pdf detach.
|
2022-07-20 04:15:41 -04:00
|
|
|
// Let the pdfCachingMetrics round trip to account for pdf-detach.
|
2022-07-18 06:24:31 -04:00
|
|
|
let isFirstRender = true
|
2022-07-20 04:15:41 -04:00
|
|
|
function firstRenderDone({ latencyFetch, latencyRender, pdfCachingMetrics }) {
|
2022-07-18 06:24:31 -04:00
|
|
|
if (!isFirstRender) return
|
|
|
|
isFirstRender = false
|
|
|
|
|
2022-08-11 05:19:26 -04:00
|
|
|
deliveryLatencies.totalDeliveryTime = Math.ceil(performance.now() - t0)
|
2022-06-21 08:15:26 -04:00
|
|
|
deliveryLatencies.latencyFetch = latencyFetch
|
2022-07-18 06:24:31 -04:00
|
|
|
if (latencyRender) {
|
2022-06-21 08:15:26 -04:00
|
|
|
deliveryLatencies.latencyRender = latencyRender
|
2021-06-01 09:53:14 -04:00
|
|
|
}
|
2022-07-20 04:32:05 -04:00
|
|
|
if (trackPdfDownloadEnabled) {
|
2022-07-18 06:24:31 -04:00
|
|
|
// Submit latency along with compile context.
|
2022-06-21 08:15:26 -04:00
|
|
|
submitCompileMetrics({
|
2022-10-25 05:24:11 -04:00
|
|
|
pdfCachingMinChunkSize,
|
2022-08-11 05:19:26 -04:00
|
|
|
...deliveryLatencies,
|
2022-07-20 04:15:41 -04:00
|
|
|
...pdfCachingMetrics,
|
2022-06-21 08:15:26 -04:00
|
|
|
})
|
2022-07-18 06:24:31 -04:00
|
|
|
}
|
2022-06-21 08:15:26 -04:00
|
|
|
}
|
2021-05-21 07:32:07 -04:00
|
|
|
|
|
|
|
return {
|
2022-06-21 08:15:26 -04:00
|
|
|
deliveryLatencies,
|
2021-05-21 07:32:07 -04:00
|
|
|
firstRenderDone,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function submitCompileMetrics(metrics) {
|
2021-06-01 09:52:55 -04:00
|
|
|
const leanMetrics = {
|
2021-06-14 05:05:03 -04:00
|
|
|
version: VERSION,
|
2022-07-18 06:24:31 -04:00
|
|
|
...metrics,
|
2022-07-08 04:15:13 -04:00
|
|
|
id: EDITOR_SESSION_ID,
|
2021-06-01 09:52:55 -04:00
|
|
|
}
|
2023-09-27 05:45:49 -04:00
|
|
|
debugConsole.log('/event/compile-metrics', JSON.stringify(leanMetrics))
|
2022-07-08 04:15:13 -04:00
|
|
|
sendMB('compile-metrics-v6', leanMetrics)
|
2021-05-21 07:32:07 -04:00
|
|
|
}
|