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