Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(logger): calculate loading latency from iframe init to render #248

Merged
merged 9 commits into from
Mar 27, 2024
11 changes: 5 additions & 6 deletions src/App.res
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
@react.component
let make = () => {
let (logger, initTimestamp) = React.useMemo0(() => {
let logger = OrcaLogger.make()
(logger, Js.Date.now())
vsrivatsa-edinburgh marked this conversation as resolved.
Show resolved Hide resolved
})
let url = RescriptReactRouter.useUrl()
let (integrateError, setIntegrateErrorError) = React.useState(() => false)
let setLoggerState = Recoil.useSetRecoilState(RecoilAtoms.loggerAtom)

let paymentMode = CardUtils.getQueryParamsDictforKey(url.search, "componentName")
let fullscreenMode = CardUtils.getQueryParamsDictforKey(url.search, "fullscreenType")

let logger = React.useMemo0(() => {
let log = OrcaLogger.make()
log
})

React.useEffect(() => {
setLoggerState(_ => logger)
None
Expand Down Expand Up @@ -39,7 +38,7 @@ let make = () => {
| "sepaBankTransfer" =>
<BankTransfersPopup transferType=fullscreenMode />
| _ =>
<LoaderController paymentMode setIntegrateErrorError logger>
<LoaderController paymentMode setIntegrateErrorError logger initTimestamp>
<Payment paymentMode integrateError logger />
</LoaderController>
}
Expand Down
6 changes: 3 additions & 3 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Utils
@react.component
let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTimestamp) => {
open RecoilAtoms
//<...>//
let (configAtom, setConfig) = Recoil.useRecoilState(configAtom)
Expand Down Expand Up @@ -257,8 +257,8 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
})
}
}

logger.setLogInfo(~value=Window.href, ~eventName=APP_RENDERED, ())
let latency = Js.Date.now() -. initTimestamp
logger.setLogInfo(~value=Window.href, ~eventName=APP_RENDERED, ~latency, ())
[
("iframeId", "no-element"->JSON.Encode.string),
("publishableKey", ""->JSON.Encode.string),
Expand Down
15 changes: 13 additions & 2 deletions src/orca-log-catcher/OrcaLogger.res
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ type setLogInfo = (
~internalMetadata: string=?,
~eventName: eventName,
~timestamp: string=?,
~latency: float=?,
~logType: logType=?,
~logCategory: logCategory=?,
~paymentMethod: string=?,
Expand Down Expand Up @@ -198,6 +199,7 @@ let defaultLoggerConfig = {
~internalMetadata as _=?,
~eventName as _,
~timestamp as _=?,
~latency as _=?,
~logType as _=?,
~logCategory as _=?,
~paymentMethod as _=?,
Expand All @@ -219,6 +221,7 @@ let defaultLoggerConfig = {
~internalMetadata as _=?,
~eventName as _,
~timestamp as _=?,
~latency as _=?,
~logType as _=?,
~logCategory as _=?,
~paymentMethod as _=?,
Expand Down Expand Up @@ -558,14 +561,18 @@ let make = (
~internalMetadata="",
~eventName,
~timestamp=?,
~latency=?,
~logType=INFO,
~logCategory=USER_EVENT,
~paymentMethod="",
(),
) => {
let eventNameStr = eventName->eventNameToStrMapper
let firstEvent = events.contents->Dict.get(eventNameStr)->Option.isNone
let latency = calculateLatencyHook(~eventName, ())
let latency = switch latency {
| Some(lat) => lat->Float.toString
| None => calculateLatencyHook(~eventName, ())
}
let localTimestamp = timestamp->Option.getOr(Date.now()->Belt.Float.toString)
let localTimestampFloat = localTimestamp->Belt.Float.fromString->Option.getOr(Date.now())
{
Expand Down Expand Up @@ -657,14 +664,18 @@ let make = (
~internalMetadata="",
~eventName,
~timestamp=?,
~latency=?,
~logType=ERROR,
~logCategory=USER_ERROR,
~paymentMethod="",
(),
) => {
let eventNameStr = eventName->eventNameToStrMapper
let firstEvent = events.contents->Dict.get(eventNameStr)->Option.isNone
let latency = calculateLatencyHook(~eventName, ())
let latency = switch latency {
| Some(lat) => lat->Float.toString
| None => calculateLatencyHook(~eventName, ())
}
let localTimestamp = timestamp->Option.getOr(Date.now()->Belt.Float.toString)
let localTimestampFloat = localTimestamp->Belt.Float.fromString->Option.getOr(Date.now())
{
Expand Down
Loading