Skip to content

Commit

Permalink
fix: app rendered event latency calculation (#273)
Browse files Browse the repository at this point in the history
Co-authored-by: Pritish Budhiraja <1805317@kiit.ac.in>
  • Loading branch information
vsrivatsa-edinburgh and Pritish Budhiraja authored Apr 4, 2024
1 parent 9bf47c1 commit e3509f0
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
showCardFormByDefault && Utils.checkPriorityList(paymentMethodOrder) ? SemiLoaded : Loading
| x => x
}
let finalLoadLatency = Date.now() -. launchTime
let finalLoadLatency = if launchTime <= 0.0 {
-1.0
} else {
Date.now() -. launchTime
}
switch updatedState {
| Loaded(_) =>
logger.setLogInfo(~value="Loaded", ~eventName=LOADER_CHANGED, ~latency=finalLoadLatency, ())
Expand Down Expand Up @@ -263,8 +267,9 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
})
}
}
setLaunchTime(_ => dict->Utils.getFloat("launchTime", 0.0))
let initLoadlatency = Date.now() -. launchTime
let newLaunchTime = dict->Utils.getFloat("launchTime", 0.0)
setLaunchTime(_ => newLaunchTime)
let initLoadlatency = Date.now() -. newLaunchTime
logger.setLogInfo(
~value=Window.href,
~eventName=APP_RENDERED,
Expand Down Expand Up @@ -357,7 +362,11 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
}
if dict->getDictIsSome("paymentMethodList") {
let list = dict->getJsonObjectFromDict("paymentMethodList")
let finalLoadlatency = Date.now() -. launchTime
let finalLoadLatency = if launchTime <= 0.0 {
-1.0
} else {
Date.now() -. launchTime
}
let updatedState: PaymentType.loadType =
list == Dict.make()->JSON.Encode.object
? LoadError(list)
Expand All @@ -375,14 +384,14 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
logger.setLogInfo(
~value="Loaded",
~eventName=LOADER_CHANGED,
~latency=finalLoadlatency,
~latency=finalLoadLatency,
(),
)
| LoadError(x) =>
logger.setLogError(
~value="LoadError: " ++ x->JSON.stringify,
~eventName=LOADER_CHANGED,
~latency=finalLoadlatency,
~latency=finalLoadLatency,
(),
)
| _ => ()
Expand All @@ -398,7 +407,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
? logger.setLogInfo(
~value="Loaded",
~eventName=LOADER_CHANGED,
~latency=finalLoadlatency,
~latency=finalLoadLatency,
(),
)
: evalMethodsList()
Expand All @@ -414,22 +423,26 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
...prev,
customerPaymentMethods,
})
let finalLoadlatency = Date.now() -. launchTime
let finalLoadLatency = if launchTime <= 0.0 {
-1.0
} else {
Date.now() -. launchTime
}

let evalMethodsList = () =>
switch paymentlist {
| Loaded(_) =>
logger.setLogInfo(
~value="Loaded",
~eventName=LOADER_CHANGED,
~latency=finalLoadlatency,
~latency=finalLoadLatency,
(),
)
| LoadError(x) =>
logger.setLogError(
~value="LoadError: " ++ x->JSON.stringify,
~eventName=LOADER_CHANGED,
~latency=finalLoadlatency,
~latency=finalLoadLatency,
(),
)

Expand All @@ -443,7 +456,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
? logger.setLogInfo(
~value="Loaded",
~eventName=LOADER_CHANGED,
~latency=finalLoadlatency,
~latency=finalLoadLatency,
(),
)
: evalMethodsList()
Expand Down

0 comments on commit e3509f0

Please sign in to comment.