Skip to content

Commit

Permalink
Pull request #244: Bugfix/removing values from logs
Browse files Browse the repository at this point in the history
Merge in EXC/orca-elements from bugfix/removing-values-from-logs to master

* commit 'bb0ae458a913786219ef1040dd6d1a9832149860':
  Added STRIPE_ELEMENTS_CALLED in list of priority events
  Minor change
  Remove unused variants/code chunks
  Added internal metadata field, 	Log exceptions as json directly :( , Remove payloads from log (value)
  • Loading branch information
Vrishab Srivatsa authored and prafulkoppalkar committed Oct 4, 2023
1 parent 732802c commit 5e24457
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let make = () => {
let fullscreenMode = CardUtils.getQueryParamsDictforKey(url.search, "fullscreenType")

let logger = React.useMemo0(() => {
let log = OrcaLogger.make(~component=paymentMode, ())
let log = OrcaLogger.make()
setLoggerState(._ => log)
log
})
Expand Down
6 changes: 1 addition & 5 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
dict->CommonHooks.updateKeys(keyPair, setKeys)
})

logger.setLogInfo(
~value=dict->Js.Json.object_->Js.Json.stringify,
~eventName=PAYMENT_OPTIONS_PROVIDED,
(),
)
logger.setLogInfo(~eventName=PAYMENT_OPTIONS_PROVIDED, ~value="", ())
}
}
} else if dict->getDictIsSome("paymentElementsUpdate") {
Expand Down
5 changes: 1 addition & 4 deletions src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ let make = (
}
if selectedOption !== "" {
loggerState.setLogInfo(
~value=[("selectedOption", selectedOption->Js.Json.string)]
->Js.Dict.fromArray
->Js.Json.object_
->Js.Json.stringify,
~value="",
~eventName=PAYMENT_METHOD_CHANGED,
~paymentMethod=selectedOption->Js.String2.toUpperCase,
(),
Expand Down
51 changes: 31 additions & 20 deletions src/Utilities/LoggerUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,37 @@ let logApi = (
(),
) => {
let logtype = getLogtype(type_)
let value = switch logtype {
| Request => [("url", url->Js.Json.string)]
| Response => [
("url", url->Js.Json.string),
("statusCode", statusCode->Js.Json.string),
("response", data),
]
| NoResponse => [
("url", url->Js.Json.string),
("statusCode", "504"->Js.Json.string),
("response", data),
]
| Err => [
("url", url->Js.Json.string),
("statusCode", statusCode->Js.Json.string),
("response", data),
]
| Method => [("method", paymentMethod->Js.Json.string), ("result", result)]
let (value, internalMetadata) = switch logtype {
| Request => ([("url", url->Js.Json.string)], [])
| Response => (
[("url", url->Js.Json.string), ("statusCode", statusCode->Js.Json.string)],
[("response", data)],
)
| NoResponse => (
[("url", url->Js.Json.string), ("statusCode", "504"->Js.Json.string), ("response", data)],
[("response", data)],
)
| Err => (
[
("url", url->Js.Json.string),
("statusCode", statusCode->Js.Json.string),
("response", data),
],
[("response", data)],
)
| Method => ([("method", paymentMethod->Js.Json.string)], [("result", result)])
}
switch optLogger {
| Some(logger) =>
logger.setLogApi(~eventName, ~value=ArrayType(value), ~logType, ~logCategory, ~type_, ())
logger.setLogApi(
~eventName,
~value=ArrayType(value),
~internalMetadata=ArrayType(internalMetadata),
~logType,
~logCategory,
~type_,
(),
)
logger.sendLogs()
| None => ()
}
Expand All @@ -65,11 +74,13 @@ let logInputChangeInfo = (text, logger: OrcaLogger.loggerMake) => {
let handleLogging = (
~optLogger: option<OrcaLogger.loggerMake>,
~value,
~internalMetadata="",
~eventName,
~paymentMethod,
(),
) => {
switch optLogger {
| Some(logger) => logger.setLogInfo(~value, ~eventName, ~paymentMethod, ())
| Some(logger) => logger.setLogInfo(~value, ~internalMetadata, ~eventName, ~paymentMethod, ())
| _ => ()
}
}
52 changes: 22 additions & 30 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ let intentCall = (
~value=data->Js.Json.stringify,
~eventName=PAYMENT_FAILED,
~paymentMethod,
(),
)
}
logApi(
Expand Down Expand Up @@ -211,9 +212,11 @@ let intentCall = (
if intent.nextAction.type_ == "redirect_to_url" {
handleLogging(
~optLogger,
~value=intent.nextAction.redirectToUrl,
~value="",
~internalMetadata=intent.nextAction.redirectToUrl,
~eventName=REDIRECTING_USER,
~paymentMethod,
(),
)
openUrl(intent.nextAction.redirectToUrl)
} else if intent.nextAction.type_ == "display_bank_transfer_information" {
Expand All @@ -226,9 +229,11 @@ let intentCall = (
dict->Js.Dict.set("url", url.href->Js.Json.string)
handleLogging(
~optLogger,
~value=dict->Js.Json.object_->Js.Json.stringify,
~value="",
~internalMetadata=dict->Js.Json.object_->Js.Json.stringify,
~eventName=DISPLAY_BANK_TRANSFER_INFO_PAGE,
~paymentMethod,
(),
)
handlePostMessage([
("fullscreen", true->Js.Json.boolean),
Expand All @@ -253,9 +258,11 @@ let intentCall = (
]->Js.Dict.fromArray
handleLogging(
~optLogger,
~value=metaData->Js.Json.object_->Js.Json.stringify,
~value="",
~internalMetadata=metaData->Js.Json.object_->Js.Json.stringify,
~eventName=DISPLAY_QR_CODE_INFO_PAGE,
~paymentMethod,
(),
)
handlePostMessage([
("fullscreen", true->Js.Json.boolean),
Expand Down Expand Up @@ -318,13 +325,15 @@ let intentCall = (
~value=intent.status,
~eventName=PAYMENT_SUCCESS,
~paymentMethod,
(),
)
} else if intent.status === "failed" {
handleLogging(
~optLogger,
~value=intent.status,
~eventName=PAYMENT_FAILED,
~paymentMethod,
(),
)
}
if intent.status === "failed" {
Expand Down Expand Up @@ -467,55 +476,38 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, paymentType: p
])
let uri = `${endpoint}/payments/${paymentIntentID}/confirm`
let fetchMethod = Fetch.Post
// let loggerPayload = body->Js.Dict.fromArray->Js.Json.object_->Js.Json.stringify
let loggerPayload = body->Js.Dict.fromArray->maskPayload

let callIntent = body => {
let maskedPayload =
body
->OrcaUtils.safeParseOpt
->Belt.Option.getWithDefault(Js.Json.null)
->Utils.getDictFromJson
->maskPayload
let loggerPayload =
[
("payload", maskedPayload->Js.Json.string),
(
"headers",
headers
->Js.Array2.map(header => {
let (key, value) = header
(key, value->Js.Json.string)
})
->Js.Dict.fromArray
->Js.Json.object_,
),
]
->Js.Dict.fromArray
->Js.Json.object_
->Js.Json.stringify
switch paymentType {
| Card =>
handleLogging(
~optLogger,
~value=loggerPayload,
~internalMetadata=loggerPayload,
~value="",
~eventName=PAYMENT_ATTEMPT,
~paymentMethod="CARD",
(),
)
| Applepay =>
handleLogging(
~optLogger,
~value=loggerPayload,
~value="",
~internalMetadata=loggerPayload,
~eventName=PAYMENT_ATTEMPT,
~paymentMethod="APPLE_PAY",
(),
)
| _ =>
let _ = bodyArr->Js.Array2.map(((str, json)) => {
if str === "payment_method_type" {
handleLogging(
~optLogger,
~value=loggerPayload,
~value="",
~internalMetadata=loggerPayload,
~eventName=PAYMENT_ATTEMPT,
~paymentMethod=json->Js.Json.decodeString->Belt.Option.getWithDefault(""),
(),
)
}
()
Expand Down
16 changes: 1 addition & 15 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -740,19 +740,5 @@ let arrayJsonToCamelCase = arr => {
})
}
let formatException = exc => {
let exceptionMessage = exc->toJson->getDictFromJson
let exceptionMessage =
[
(
"exception_id",
exceptionMessage->Js.Dict.get("RE_EXN_ID")->Belt.Option.getWithDefault(Js.Json.null),
),
(
"exception_message",
exceptionMessage->Js.Dict.get("_1")->Belt.Option.getWithDefault(Js.Json.null),
),
]
->Js.Dict.fromArray
->Js.Json.object_
exceptionMessage
exc->toJson
}
13 changes: 7 additions & 6 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let make = (
options,
setIframeRef,
~clientSecretId,
~sdkSessionId="",
~sdkSessionId,
~publishableKey,
~logger: option<OrcaLogger.loggerMake>,
) => {
Expand Down Expand Up @@ -280,7 +280,8 @@ let make = (
trustpay.executeGooglePayment(. payment, googlePayRequest)
->then(res => {
logger.setLogInfo(
~value="TrustPay GooglePay Success Response: " ++ res->Js.Json.stringify,
~value="TrustPay GooglePay Success Response",
~internalMetadata=res->Js.Json.stringify,
~eventName=GOOGLE_PAY_FLOW,
~paymentMethod="GOOGLE_PAY",
(),
Expand Down Expand Up @@ -448,8 +449,8 @@ let make = (
trustpay.finishApplePaymentV2(. payment, paymentRequest)
->then(res => {
logger.setLogInfo(
~value="TrustPay ApplePay Success Response: " ++
res->Js.Json.stringify,
~value="TrustPay ApplePay Success Response",
~internalMetadata=res->Js.Json.stringify,
~eventName=APPLE_PAY_FLOW,
~paymentMethod="APPLE_PAY",
(),
Expand Down Expand Up @@ -480,9 +481,9 @@ let make = (
})
->ignore
} catch {
| _ => {
| exn => {
logger.setLogInfo(
~value="TrustPay API initialising error",
~value=exn->Utils.formatException->Js.Json.stringify,
~eventName=APPLE_PAY_FLOW,
~paymentMethod="APPLE_PAY",
(),
Expand Down
1 change: 0 additions & 1 deletion src/orca-loader/Hyper.res
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ let make = (publishableKey, _options: option<Js.Json.t>, analyticsInfo: option<J
let sessionID = analyticsInfoDict->getString("sessionID", "")
let sdkTimestamp = analyticsInfoDict->getString("timeStamp", Js.Date.now()->Belt.Float.toString)
let logger = OrcaLogger.make(
~component="loader",
~sessionId=sessionID,
~source=Loader,
~merchantId=publishableKey,
Expand Down
2 changes: 1 addition & 1 deletion src/orca-log-catcher/ErrorBoundary.res
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ module ErrorCard = {
sessionId: "",
source: "orca-elements",
version: GlobalVars.repoVersion,
component: "payment",
value: error->errorToJson->Js.Json.stringify,
internalMetadata: "",
category: USER_ERROR,
paymentId: "",
merchantId: "",
Expand Down
Loading

0 comments on commit 5e24457

Please sign in to comment.