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

use new metric helpers #185

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
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
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 @@
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 @@
};
});

logger.addMetricDimensionBuilder(() => payPalWebV5Dimensions);

ZalgoPromise.onPossiblyUnhandledException((err) => {
logger.track({
[FPTI_KEY.ERROR_CODE]: "payments_sdk_error",
Expand Down Expand Up @@ -168,11 +171,10 @@
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,

Check warning on line 177 in src/tracking.js

View check run for this annotation

Codecov / codecov/patch

src/tracking.js#L174-L177

Added lines #L174 - L177 were not covered by tests
// dimensions: {
// cacheType,
// version,
Expand All @@ -181,20 +183,6 @@
// token: getTokenType(),
// },
// })
// $FlowIssue
Copy link
Contributor

Choose a reason for hiding this comment

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

type safety ++ !

.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 @@
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(),
},
});
});
}
Loading