From 35100bafe840dfad00937232fb28d85e005c8c16 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Thu, 7 Dec 2023 10:28:48 +0530 Subject: [PATCH] chore: add stats for shopify anonId resolution based on shopifyTopic and method --- src/util/prometheus.js | 6 ++++++ src/v0/sources/shopify/transform.js | 2 +- src/v0/sources/shopify/util.js | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/util/prometheus.js b/src/util/prometheus.js index 116f77d214..ec8ad61789 100644 --- a/src/util/prometheus.js +++ b/src/util/prometheus.js @@ -487,6 +487,12 @@ class Prometheus { type: 'counter', labelNames: ['type', 'writeKey', 'source'], }, + { + name: 'shopify_anon_id_resolve', + help: 'shopify_anon_id_resolve', + type: 'counter', + labelNames: ['method', 'writeKey', 'shopifyTopic'], + }, { name: 'shopify_redis_calls', help: 'shopify_redis_calls', diff --git a/src/v0/sources/shopify/transform.js b/src/v0/sources/shopify/transform.js index fd763eeb46..013580d7a3 100644 --- a/src/v0/sources/shopify/transform.js +++ b/src/v0/sources/shopify/transform.js @@ -175,7 +175,7 @@ const processEvent = async (inputEvent, metricMetadata) => { if (message.type !== EventType.IDENTIFY) { const { anonymousId, sessionId } = await getAnonymousIdAndSessionId( message, - metricMetadata, + { shopifyTopic, ...metricMetadata }, redisData, ); if (isDefinedAndNotNull(anonymousId)) { diff --git a/src/v0/sources/shopify/util.js b/src/v0/sources/shopify/util.js index 61501bdab6..6f31ade4a7 100644 --- a/src/v0/sources/shopify/util.js +++ b/src/v0/sources/shopify/util.js @@ -164,6 +164,10 @@ const getAnonymousIdAndSessionId = async (message, metricMetadata, redisData = n } // falling back to cartToken mapping or its hash in case no rudderAnonymousId or rudderSessionId is found if (isDefinedAndNotNull(anonymousId) && isDefinedAndNotNull(sessionId)) { + stats.increment('shopify_anon_id_resolve', { + method: 'note_attributes', + ...metricMetadata, + }); return { anonymousId, sessionId }; } const cartToken = getCartToken(message); @@ -189,6 +193,13 @@ const getAnonymousIdAndSessionId = async (message, metricMetadata, redisData = n Hash the id and use it as anonymousId (limiting 256 -> 36 chars) and sessionId is not sent as its not required field */ anonymousId = v5(cartToken, v5.URL); + } else { + // This metric let us know how many events based on event name used redis for anonId resolution + // and for how many + stats.increment('shopify_anon_id_resolve', { + method: 'database', + ...metricMetadata, + }); } return { anonymousId, sessionId }; };