|
|
@@ -2,6 +2,8 @@ import { v4 as uuid } from 'uuid'
|
|
|
import { sendMB } from '../../../infrastructure/event-tracking'
|
|
|
import { trackPdfDownloadEnabled } from './pdf-caching-flags'
|
|
|
import { debugConsole } from '@/utils/debugging'
|
|
|
+import { DeliveryLatencies } from './types'
|
|
|
+import { CompileResponseData } from '@ol-types/compile'
|
|
|
|
|
|
// VERSION should get incremented when making changes to caching behavior or
|
|
|
// adjusting metrics collection.
|
|
|
@@ -10,7 +12,11 @@ const VERSION = 9
|
|
|
// editing session id
|
|
|
export const EDITOR_SESSION_ID = uuid()
|
|
|
|
|
|
-const pdfCachingMetrics = {
|
|
|
+type PdfCachingMetrics = {
|
|
|
+ viewerId: string
|
|
|
+}
|
|
|
+
|
|
|
+const pdfCachingMetrics: PdfCachingMetrics = {
|
|
|
viewerId: EDITOR_SESSION_ID,
|
|
|
}
|
|
|
|
|
|
@@ -18,10 +24,21 @@ export function getPdfCachingMetrics() {
|
|
|
return pdfCachingMetrics
|
|
|
}
|
|
|
|
|
|
-export function trackPdfDownload(response, compileTimeClientE2E, t0) {
|
|
|
+export function trackPdfDownload(
|
|
|
+ response: CompileResponseData,
|
|
|
+ compileTimeClientE2E: number,
|
|
|
+ t0: number
|
|
|
+): {
|
|
|
+ deliveryLatencies: DeliveryLatencies
|
|
|
+ firstRenderDone: (args: {
|
|
|
+ latencyFetch: number
|
|
|
+ latencyRender: number | undefined
|
|
|
+ pdfCachingMetrics: typeof pdfCachingMetrics
|
|
|
+ }) => void
|
|
|
+} {
|
|
|
const { timings, pdfCachingMinChunkSize } = response
|
|
|
|
|
|
- const deliveryLatencies = {
|
|
|
+ const deliveryLatencies: DeliveryLatencies = {
|
|
|
compileTimeClientE2E,
|
|
|
compileTimeServerE2E: timings?.compileE2E,
|
|
|
}
|
|
|
@@ -30,7 +47,15 @@ export function trackPdfDownload(response, compileTimeClientE2E, t0) {
|
|
|
// E.g. two pdf detach tabs or pdf detacher plus pdf detach.
|
|
|
// Let the pdfCachingMetrics round trip to account for pdf-detach.
|
|
|
let isFirstRender = true
|
|
|
- function firstRenderDone({ latencyFetch, latencyRender, pdfCachingMetrics }) {
|
|
|
+ function firstRenderDone({
|
|
|
+ latencyFetch,
|
|
|
+ latencyRender,
|
|
|
+ pdfCachingMetrics,
|
|
|
+ }: {
|
|
|
+ latencyFetch: number
|
|
|
+ latencyRender: number | undefined
|
|
|
+ pdfCachingMetrics: PdfCachingMetrics
|
|
|
+ }) {
|
|
|
if (!isFirstRender) return
|
|
|
isFirstRender = false
|
|
|
|
|
|
@@ -55,7 +80,10 @@ export function trackPdfDownload(response, compileTimeClientE2E, t0) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function submitCompileMetrics(metrics) {
|
|
|
+type Metrics = DeliveryLatencies &
|
|
|
+ PdfCachingMetrics & { pdfCachingMinChunkSize: number }
|
|
|
+
|
|
|
+function submitCompileMetrics(metrics: Metrics) {
|
|
|
const leanMetrics = {
|
|
|
version: VERSION,
|
|
|
...metrics,
|