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

refactor: logs refactor #549

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is also optional

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this even sent in the payload?

ephemeralKey: string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is also optional

}
Expand Down Expand Up @@ -320,8 +320,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 @@ -331,9 +331,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 @@ -532,9 +535,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 @@ -677,18 +680,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 @@ -705,18 +705,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 @@ -765,7 +762,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 @@ -822,7 +819,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 @@ -869,7 +866,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 @@ -897,16 +894,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,
Copy link
Member

@vsrivatsa-edinburgh vsrivatsa-edinburgh Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will log the hostname of the iframe
This is not the expected behaviour

Consume hostname of parent from Elements over a postmessage

latency,
paymentMethod: "",
firstEvent,
metadata: metadata.contents,
ephemeralKey: ephemeralKey.contents,
Expand Down
Loading