Skip to content

Commit

Permalink
feat:HS-186: added metadata support for logs (#88)
Browse files Browse the repository at this point in the history
Co-authored-by: arun.mishra <[email protected]>
  • Loading branch information
arun-mi and arun.mishra authored Jan 3, 2024
1 parent 587689b commit 8097a1e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 30 deletions.
6 changes: 5 additions & 1 deletion src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
let publishableKey = dict->getString("publishableKey", "")
logger.setMerchantId(publishableKey)
}

if dict->getDictIsSome("endpoint") {
let endpoint = dict->getString("endpoint", "")
ApiEndpoint.setApiEndPoint(endpoint)
}

if dict->getDictIsSome("analyticsMetadata") {
let metadata = dict->getJsonObjectFromDict("analyticsMetadata")
logger.setMetadata(metadata)
}
if dict->getDictIsSome("paymentOptions") {
let paymentOptions = dict->Utils.getDictFromObj("paymentOptions")

Expand Down
2 changes: 2 additions & 0 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let make = (
~sdkSessionId,
~publishableKey,
~logger: option<OrcaLogger.loggerMake>,
~analyticsMetadata,
) => {
let handleApplePayMessages = ref(_ => ())
let applePaySessionRef = ref(Js.Nullable.null)
Expand Down Expand Up @@ -225,6 +226,7 @@ let make = (
("sdkSessionId", sdkSessionId->Js.Json.string),
("sdkHandleConfirmPayment", sdkHandleConfirmPayment->Js.Json.boolean),
("parentURL", "*"->Js.Json.string),
("analyticsMetadata", analyticsMetadata),
]->Js.Dict.fromArray

let handleApplePayMounted = (event: Types.event) => {
Expand Down
8 changes: 8 additions & 0 deletions src/orca-loader/Hyper.res
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ let make = (publishableKey, options: option<Js.Json.t>, analyticsInfo: option<Js
->Belt.Option.getWithDefault(Js.Json.null)
->Utils.getDictFromJson
->Utils.getBool("isPreloadEnabled", true)
let analyticsMetadata =
options
->Belt.Option.getWithDefault(Js.Json.null)
->Utils.getDictFromJson
->Utils.getDictFromObj("analytics")
->Utils.getJsonObjectFromDict("metadata")
if isPreloadEnabled {
preloader()
}
Expand All @@ -88,6 +94,7 @@ let make = (publishableKey, options: option<Js.Json.t>, analyticsInfo: option<Js
~sessionId=sessionID,
~source=Loader,
~merchantId=publishableKey,
~metadata=analyticsMetadata,
(),
)
switch options {
Expand Down Expand Up @@ -336,6 +343,7 @@ let make = (publishableKey, options: option<Js.Json.t>, analyticsInfo: option<Js
~sdkSessionId=sessionID,
~publishableKey,
~logger=Some(logger),
~analyticsMetadata,
)
}
let confirmCardPaymentFn =
Expand Down
1 change: 1 addition & 0 deletions src/orca-log-catcher/ErrorBoundary.res
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ module ErrorCard = {
latency: "",
paymentMethod: "",
firstEvent: false,
metadata: Js.Json.null,
}
beaconApiCall([errorLog])
}
Expand Down
79 changes: 50 additions & 29 deletions src/orca-log-catcher/OrcaLogger.res
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ type logFile = {
latency: string,
firstEvent: bool,
paymentMethod: string,
metadata: Js.Json.t,
}

type setlogApiValueType =
Expand Down Expand Up @@ -175,6 +176,7 @@ type loggerMake = {
setSessionId: string => unit,
setClientSecret: string => unit,
setMerchantId: string => unit,
setMetadata: Js.Json.t => unit,
}

let defaultLoggerConfig = {
Expand Down Expand Up @@ -215,6 +217,7 @@ let defaultLoggerConfig = {
setLogInitiated: () => (),
setMerchantId: _x => (),
setSessionId: _x => (),
setMetadata: _x => (),
}

let logFileToObj = logFile => {
Expand Down Expand Up @@ -374,7 +377,14 @@ let browserDetect = content => {

let arrayOfNameAndVersion = Js.String2.split(Window.userAgent->browserDetect, "-")

let make = (~sessionId=?, ~source: option<source>=?, ~clientSecret=?, ~merchantId=?, ()) => {
let make = (
~sessionId=?,
~source: option<source>=?,
~clientSecret=?,
~merchantId=?,
~metadata=?,
(),
) => {
let loggingLevel = switch GlobalVars.loggingLevelStr {
| "DEBUG" => DEBUG
| "INFO" => INFO
Expand All @@ -401,6 +411,12 @@ let make = (~sessionId=?, ~source: option<source>=?, ~clientSecret=?, ~merchantI
merchantId := value
}

let metadata = ref(metadata->Belt.Option.getWithDefault(Js.Json.null))

let setMetadata = value => {
metadata := value
}

let conditionalLogPush = (log: logFile) => {
if GlobalVars.enableLogging {
switch loggingLevel {
Expand Down Expand Up @@ -532,13 +548,13 @@ let make = (~sessionId=?, ~source: option<source>=?, ~clientSecret=?, ~merchantI
let localTimestampFloat =
localTimestamp->Belt.Float.fromString->Belt.Option.getWithDefault(Js.Date.now())
{
logType: logType,
logType,
timestamp: localTimestamp,
sessionId: sessionId.contents,
source: sourceString,
version: GlobalVars.repoVersion,
value: value,
internalMetadata: internalMetadata,
value,
internalMetadata,
category: logCategory,
paymentId: Js.String2.split(clientSecret.contents, "_secret_")
->Belt.Array.get(0)
Expand All @@ -550,9 +566,10 @@ let make = (~sessionId=?, ~source: option<source>=?, ~clientSecret=?, ~merchantI
userAgent: Window.userAgent,
appId: "",
eventName: eventNameStr,
latency: latency,
paymentMethod: paymentMethod,
firstEvent: firstEvent,
latency,
paymentMethod,
firstEvent,
metadata: metadata.contents,
}
->conditionalLogPush
->ignore
Expand Down Expand Up @@ -584,7 +601,7 @@ let make = (~sessionId=?, ~source: option<source>=?, ~clientSecret=?, ~merchantI
let localTimestampFloat =
localTimestamp->Belt.Float.fromString->Belt.Option.getWithDefault(Js.Date.now())
{
logType: logType,
logType,
timestamp: localTimestamp,
sessionId: sessionId.contents,
source: sourceString,
Expand All @@ -608,9 +625,10 @@ let make = (~sessionId=?, ~source: option<source>=?, ~clientSecret=?, ~merchantI
userAgent: Window.userAgent,
appId: "",
eventName: eventNameStr,
latency: latency,
paymentMethod: paymentMethod,
firstEvent: firstEvent,
latency,
paymentMethod,
firstEvent,
metadata: metadata.contents,
}
->conditionalLogPush
->ignore
Expand All @@ -635,13 +653,13 @@ let make = (~sessionId=?, ~source: option<source>=?, ~clientSecret=?, ~merchantI
let localTimestampFloat =
localTimestamp->Belt.Float.fromString->Belt.Option.getWithDefault(Js.Date.now())
{
logType: logType,
logType,
timestamp: localTimestamp,
sessionId: sessionId.contents,
source: sourceString,
version: GlobalVars.repoVersion,
value: value,
internalMetadata: internalMetadata,
value,
internalMetadata,
category: logCategory,
paymentId: Js.String2.split(clientSecret.contents, "_secret_")
->Belt.Array.get(0)
Expand All @@ -653,9 +671,10 @@ let make = (~sessionId=?, ~source: option<source>=?, ~clientSecret=?, ~merchantI
userAgent: Window.userAgent,
appId: "",
eventName: eventNameStr,
latency: latency,
paymentMethod: paymentMethod,
firstEvent: firstEvent,
latency,
paymentMethod,
firstEvent,
metadata: metadata.contents,
}
->conditionalLogPush
->ignore
Expand All @@ -669,7 +688,7 @@ let make = (~sessionId=?, ~source: option<source>=?, ~clientSecret=?, ~merchantI
let latency = calculateLatencyHook(~eventName, ())
{
logType: INFO,
eventName: eventName,
eventName,
timestamp: Js.Date.now()->Belt.Float.toString,
sessionId: sessionId.contents,
source: sourceString,
Expand All @@ -686,9 +705,10 @@ let make = (~sessionId=?, ~source: option<source>=?, ~clientSecret=?, ~merchantI
platform: Window.platform,
userAgent: Window.userAgent,
appId: "",
latency: latency,
latency,
paymentMethod: "",
firstEvent: firstEvent,
firstEvent,
metadata: metadata.contents,
}
->conditionalLogPush
->ignore
Expand All @@ -707,14 +727,15 @@ let make = (~sessionId=?, ~source: option<source>=?, ~clientSecret=?, ~merchantI
Window.addEventListener("beforeunload", handleBeforeUnload)

{
setLogInfo: setLogInfo,
setLogInitiated: setLogInitiated,
setConfirmPaymentValue: setConfirmPaymentValue,
sendLogs: sendLogs,
setSessionId: setSessionId,
setClientSecret: setClientSecret,
setMerchantId: setMerchantId,
setLogApi: setLogApi,
setLogError: setLogError,
setLogInfo,
setLogInitiated,
setConfirmPaymentValue,
sendLogs,
setSessionId,
setClientSecret,
setMerchantId,
setMetadata,
setLogApi,
setLogError,
}
}

0 comments on commit 8097a1e

Please sign in to comment.