Skip to content

Commit

Permalink
use new metric helpers (#185)
Browse files Browse the repository at this point in the history
* use new metric helpers

* js doc deprecated message
  • Loading branch information
wsbrunson committed Feb 15, 2024
1 parent c1b139a commit 9da22a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Logger, type LoggerType } from "@krakenjs/beaver-logger/src";
import { memoize } from "@krakenjs/belter/src";
import { BASE_SDK_METRIC_NAMESPACE } from "@paypal/sdk-constants/src";

import { getDisableSetCookie } from "./global";
import { getPayPalLoggerUrl } from "./domains";
Expand All @@ -17,9 +18,13 @@ export const getLogger: GetLogger = memoize(() => {

return Logger({
url: loggerUrl,
metricNamespacePrefix: BASE_SDK_METRIC_NAMESPACE,
});
});

/*
* @deprecated - use logger.metricCounter instead
*/
export const sendCountMetric = ({
dimensions,
event,
Expand Down
40 changes: 21 additions & 19 deletions src/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
FPTI_DATA_SOURCE,
FPTI_SDK_NAME,
FPTI_USER_ACTION,
payPalWebV5Dimensions,
} from "@paypal/sdk-constants/src";

import { getEnv, getVersion, getCorrelationID, getComponents } from "./global";
Expand Down Expand Up @@ -125,6 +126,8 @@ export function setupLogger() {
};
});

logger.addMetricDimensionBuilder(() => payPalWebV5Dimensions);

ZalgoPromise.onPossiblyUnhandledException((err) => {
logger.track({
[FPTI_KEY.ERROR_CODE]: "payments_sdk_error",
Expand Down Expand Up @@ -168,11 +171,10 @@ export function setupLogger() {
logger
// We can not send gauge metrics to our logger backend currently
// once we have that ability, we should uncomment this gauge metric
// .metric({
// metricNamespace: "pp.app.paypal_sdk.init.gauge",
// metricType: "gauge",
// metricEventName: "load_performance",
// metricValue: sdkLoadTime,
// .metricGauge({
// namespace: "sdk_client.init.gauge",
// event: "load_performance",
// value: sdkLoadTime,
// dimensions: {
// cacheType,
// version,
Expand All @@ -181,20 +183,6 @@ export function setupLogger() {
// token: getTokenType(),
// },
// })
// $FlowIssue
.metric({
metricNamespace: "pp.app.paypal_sdk.init.count",
metricEventName: "load",
dimensions: {
integrationSource,
pageType,
userAction,
version,
components: getComponents().join(","),
isPayPalDomain: isLoadedInFrame,
token: getTokenType(),
},
})
.track({
[FPTI_KEY.TRANSITION]: "process_js_sdk_init_client",
[FPTI_KEY.SDK_LOAD_TIME]: sdkLoadTime,
Expand All @@ -205,5 +193,19 @@ export function setupLogger() {
if (isIEIntranet()) {
logger.warn("ie_intranet_mode");
}

logger.metricCounter({
namespace: "sdk_client.init.count",
event: "init",
dimensions: {
integrationSource,
pageType,
userAction,
version,
components: getComponents().join(","),
isPayPalDomain: isLoadedInFrame,
token: getTokenType(),
},
});
});
}

0 comments on commit 9da22a4

Please sign in to comment.