Skip to content

Commit

Permalink
refactor: logs refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanskar2001 committed Aug 8, 2024
1 parent a9c1a6e commit f590197
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions src/orca-log-catcher/OrcaLogger.res
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ type logFile = {
category: logCategory,
source: string,
version: string,
value: string,
internalMetadata: string,
value?: string,
internalMetadata?: string,
sessionId: string,
merchantId: string,
paymentId: string,
Expand All @@ -205,9 +205,9 @@ type logFile = {
browserVersion: string,
userAgent: string,
eventName: eventName,
latency: string,
latency?: string,
firstEvent: bool,
paymentMethod: string,
paymentMethod?: string,
metadata: JSON.t,
ephemeralKey: string,
}
Expand Down Expand Up @@ -325,8 +325,8 @@ let logFileToObj = logFile => {
),
("source", logFile.source->convertToScreamingSnakeCase->JSON.Encode.string),
("version", logFile.version->JSON.Encode.string), // repoversion of orca-android
("value", logFile.value->JSON.Encode.string),
("internal_metadata", logFile.internalMetadata->JSON.Encode.string),
("value", logFile.value->Option.getOr("")->JSON.Encode.string),
("internal_metadata", logFile.internalMetadata->Option.getOr("")->JSON.Encode.string),
("session_id", logFile.sessionId->JSON.Encode.string),
("merchant_id", logFile.merchantId->JSON.Encode.string),
("payment_id", logFile.paymentId->JSON.Encode.string),
Expand All @@ -336,9 +336,12 @@ let logFileToObj = logFile => {
("event_name", logFile.eventName->eventNameToStrMapper->JSON.Encode.string),
("browser_name", logFile.browserName->convertToScreamingSnakeCase->JSON.Encode.string),
("browser_version", logFile.browserVersion->JSON.Encode.string),
("latency", logFile.latency->JSON.Encode.string),
("latency", logFile.latency->Option.getOr("")->JSON.Encode.string),
("first_event", (logFile.firstEvent ? "true" : "false")->JSON.Encode.string),
("payment_method", logFile.paymentMethod->convertToScreamingSnakeCase->JSON.Encode.string),
(
"payment_method",
logFile.paymentMethod->Option.getOr("")->convertToScreamingSnakeCase->JSON.Encode.string,
),
]
->Dict.fromArray
->JSON.Encode.object
Expand Down Expand Up @@ -538,9 +541,9 @@ let make = (
let maxLogsPushedPerEventName = GlobalVars.maxLogsPushedPerEventName
let conditionalEventName = switch log.eventName {
| INPUT_FIELD_CHANGED => log.value // to enforce rate limiting for each input field independently
| _ => ""
| _ => Some("")
}
let eventName = log.eventName->eventNameToStrMapper ++ conditionalEventName
let eventName = log.eventName->eventNameToStrMapper ++ conditionalEventName->Option.getOr("")

let counter = eventName->calculateAndUpdateCounterHook
if GlobalVars.enableLogging && counter <= maxLogsPushedPerEventName {
Expand Down Expand Up @@ -686,18 +689,15 @@ let make = (
sessionId: sessionId.contents,
source: sourceString,
version: GlobalVars.repoVersion,
value: "",
internalMetadata: "",
category: USER_EVENT,
paymentId: clientSecret.contents->getPaymentId,
merchantId: merchantId.contents,
browserName: arrayOfNameAndVersion->Array.get(0)->Option.getOr("Others"),
browserVersion: arrayOfNameAndVersion->Array.get(1)->Option.getOr("0"),
platform: Window.Navigator.platform,
userAgent: Window.Navigator.userAgent,
appId: "",
appId: Window.Location.hostname,
eventName: PAYMENT_METHOD_CHANGED,
latency: "",
paymentMethod,
firstEvent: true,
metadata: metadata.contents,
Expand All @@ -714,18 +714,15 @@ let make = (
sessionId: sessionId.contents,
source: sourceString,
version: GlobalVars.repoVersion,
value: "",
internalMetadata: "",
category: USER_EVENT,
paymentId: clientSecret.contents->getPaymentId,
merchantId: merchantId.contents,
browserName: arrayOfNameAndVersion->Array.get(0)->Option.getOr("Others"),
browserVersion: arrayOfNameAndVersion->Array.get(1)->Option.getOr("0"),
platform: Window.Navigator.platform,
userAgent: Window.Navigator.userAgent,
appId: "",
appId: Window.Location.hostname,
eventName: PAYMENT_DATA_FILLED,
latency: "",
paymentMethod,
firstEvent: true,
metadata: metadata.contents,
Expand Down Expand Up @@ -775,7 +772,7 @@ let make = (
browserVersion: arrayOfNameAndVersion->Array.get(1)->Option.getOr("0"),
platform: Window.Navigator.platform,
userAgent: Window.Navigator.userAgent,
appId: "",
appId: Window.Location.hostname,
eventName,
latency,
paymentMethod,
Expand Down Expand Up @@ -833,7 +830,7 @@ let make = (
browserVersion: arrayOfNameAndVersion->Array.get(1)->Option.getOr("0"),
platform: Window.Navigator.platform,
userAgent: Window.Navigator.userAgent,
appId: "",
appId: Window.Location.hostname,
eventName,
latency,
paymentMethod,
Expand Down Expand Up @@ -881,7 +878,7 @@ let make = (
browserVersion: arrayOfNameAndVersion->Array.get(1)->Option.getOr("0"),
platform: Window.Navigator.platform,
userAgent: Window.Navigator.userAgent,
appId: "",
appId: Window.Location.hostname,
eventName,
latency,
paymentMethod,
Expand Down Expand Up @@ -909,16 +906,14 @@ let make = (
version: GlobalVars.repoVersion,
category: USER_EVENT,
value: "log initiated",
internalMetadata: "",
paymentId: clientSecret.contents->getPaymentId,
merchantId: merchantId.contents,
browserName: arrayOfNameAndVersion->Array.get(0)->Option.getOr("Others"),
browserVersion: arrayOfNameAndVersion->Array.get(1)->Option.getOr("0"),
platform: Window.Navigator.platform,
userAgent: Window.Navigator.userAgent,
appId: "",
appId: Window.Location.hostname,
latency,
paymentMethod: "",
firstEvent,
metadata: metadata.contents,
ephemeralKey: ephemeralKey.contents,
Expand Down

0 comments on commit f590197

Please sign in to comment.