Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/shared-code' into s…
Browse files Browse the repository at this point in the history
…hared-code
  • Loading branch information
manideepk90 committed Oct 4, 2024
2 parents a110012 + baaef9d commit e01cd34
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 29 deletions.
45 changes: 45 additions & 0 deletions shared-code/Utils/LogUtils.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
type apiLogType = Request | Response | NoResponse | Err | Method

let getApiLogValues = (
apiLogType: apiLogType,
url,
statusCode,
data,
~paymentMethod=?,
~result=?,
) => {
switch apiLogType {
| Request => ([("url", url->JSON.Encode.string)], [])
| Response => (
[("url", url->JSON.Encode.string), ("statusCode", statusCode->JSON.Encode.string)],
[("response", data)],
)
| NoResponse => (
[
("url", url->JSON.Encode.string),
("statusCode", "504"->JSON.Encode.string),
("response", data),
],
[("response", data)],
)
| Err => (
[
("url", url->JSON.Encode.string),
("statusCode", statusCode->JSON.Encode.string),
("response", data),
],
[("response", data)],
)
| Method => {
let methodValue = switch paymentMethod {
| Some(method) => method->JSON.Encode.string
| None => ""->JSON.Encode.string
}
let resultValue = switch result {
| Some(res) => res
| None => Dict.make()->JSON.Encode.object
}
([("method", methodValue)], [("result", resultValue)])
}
}
}
28 changes: 3 additions & 25 deletions src/Utilities/LoggerUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let logApi = (
~eventName,
~statusCode="",
~data: JSON.t=Dict.make()->JSON.Encode.object,
~apiLogType: OrcaLogger.apiLogType,
~apiLogType: LogUtils.apiLogType,
~url="",
~paymentMethod="",
~result: JSON.t=Dict.make()->JSON.Encode.object,
Expand All @@ -11,30 +11,8 @@ let logApi = (
~logCategory: OrcaLogger.logCategory=API,
~isPaymentSession: bool=false,
) => {
let (value, internalMetadata) = switch apiLogType {
| Request => ([("url", url->JSON.Encode.string)], [])
| Response => (
[("url", url->JSON.Encode.string), ("statusCode", statusCode->JSON.Encode.string)],
[("response", data)],
)
| NoResponse => (
[
("url", url->JSON.Encode.string),
("statusCode", "504"->JSON.Encode.string),
("response", data),
],
[("response", data)],
)
| Err => (
[
("url", url->JSON.Encode.string),
("statusCode", statusCode->JSON.Encode.string),
("response", data),
],
[("response", data)],
)
| Method => ([("method", paymentMethod->JSON.Encode.string)], [("result", result)])
}
let (value, internalMetadata) = LogUtils.getApiLogValues(apiLogType, url, statusCode, data)

switch optLogger {
| Some(logger) =>
logger.setLogApi(
Expand Down
8 changes: 4 additions & 4 deletions src/orca-log-catcher/OrcaLogger.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type apiLogType = Request | Response | NoResponse | Method | Err
// type apiLogType = Request | Response | NoResponse | Method | Err
type logType = DEBUG | INFO | ERROR | WARNING | SILENT
type logCategory = API | USER_ERROR | USER_EVENT | MERCHANT_EVENT

Expand Down Expand Up @@ -240,7 +240,7 @@ type loggerMake = {
~logType: logType=?,
~logCategory: logCategory=?,
~paymentMethod: string=?,
~apiLogType: apiLogType=?,
~apiLogType: LogUtils.apiLogType=?,
~isPaymentSession: bool=?,
) => unit,
setLogInitiated: unit => unit,
Expand Down Expand Up @@ -641,7 +641,7 @@ let make = (
}
}

let calculateLatencyHook = (~eventName, ~apiLogType=Method) => {
let calculateLatencyHook = (~eventName, ~apiLogType=LogUtils.Method) => {
let currentTimestamp = Date.now()
let latency = switch eventName {
| PAYMENT_ATTEMPT => {
Expand Down Expand Up @@ -798,7 +798,7 @@ let make = (
~logType=INFO,
~logCategory=API,
~paymentMethod="",
~apiLogType=Request,
~apiLogType=LogUtils.Request,
~isPaymentSession=false,
) => {
let eventNameStr = eventName->eventNameToStrMapper
Expand Down

0 comments on commit e01cd34

Please sign in to comment.