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

chore: add stats for shopify Id resolution #2885

Merged
merged 1 commit into from
Dec 7, 2023
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
6 changes: 6 additions & 0 deletions src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/v0/sources/shopify/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
11 changes: 11 additions & 0 deletions src/v0/sources/shopify/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 };
};
Expand Down
Loading