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-06-21 08:15:26 -04:00
|
|
|
import getMeta from '../../../utils/meta'
|
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-07-06 07:06:53 -04:00
|
|
|
const VERSION = 3
|
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-06 07:06:53 -04:00
|
|
|
let pdfCachingMetrics
|
|
|
|
|
|
|
|
export function setCachingMetrics(metrics) {
|
|
|
|
pdfCachingMetrics = metrics
|
|
|
|
}
|
|
|
|
|
2022-07-18 06:24:31 -04:00
|
|
|
export function trackPdfDownload(response, compileTimeClientE2E, t0) {
|
|
|
|
const { timings } = 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.
|
|
|
|
let isFirstRender = true
|
|
|
|
function firstRenderDone({ latencyFetch, latencyRender }) {
|
|
|
|
if (!isFirstRender) return
|
|
|
|
isFirstRender = false
|
|
|
|
|
|
|
|
const totalDeliveryTime = Math.ceil(performance.now() - t0)
|
|
|
|
deliveryLatencies.totalDeliveryTime = totalDeliveryTime
|
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-18 06:24:31 -04:00
|
|
|
if (getMeta('ol-trackPdfDownload')) {
|
|
|
|
// Submit latency along with compile context.
|
2022-06-21 08:15:26 -04:00
|
|
|
submitCompileMetrics({
|
2022-07-18 06:24:31 -04:00
|
|
|
totalDeliveryTime,
|
2022-06-21 08:15:26 -04:00
|
|
|
latencyFetch,
|
|
|
|
latencyRender,
|
|
|
|
compileTimeClientE2E,
|
|
|
|
})
|
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,
|
2022-07-06 07:06:53 -04:00
|
|
|
...(pdfCachingMetrics || {}),
|
2021-06-01 09:52:55 -04:00
|
|
|
}
|
2021-05-21 07:32:07 -04:00
|
|
|
sl_console.log('/event/compile-metrics', JSON.stringify(metrics))
|
2022-07-08 04:15:13 -04:00
|
|
|
sendMB('compile-metrics-v6', leanMetrics)
|
2021-05-21 07:32:07 -04:00
|
|
|
}
|