Skip to content

Commit

Permalink
throttle the logs a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
latter-bolden committed Jan 10, 2025
1 parent 15ddb7e commit 7d18ec1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
33 changes: 21 additions & 12 deletions packages/shared/src/store/lure.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';
import produce from 'immer';
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import create from 'zustand';

import { getCurrentUserId, poke, scry, subscribeOnce } from '../api/urbit';
Expand Down Expand Up @@ -374,6 +374,7 @@ export function useLureLinkStatus({
inviteServiceEndpoint: string;
inviteServiceIsDev: boolean;
}) {
const [lastLoggedStatus, setLastLoggedStatus] = useState('');
const { supported, fetched, enabled, url, deepLinkUrl, toggle, describe } =
useLure({
flag,
Expand Down Expand Up @@ -423,17 +424,25 @@ export function useLureLinkStatus({
return 'ready';
}, [supported, fetched, enabled, url, checked, deepLinkUrl, good, flag]);

if (status === 'error') {
lureLogger.trackEvent(AnalyticsEvent.InviteError, {
context: 'useLureLinkStatus has error status',
inviteInfo,
});
} else {
lureLogger.trackEvent(AnalyticsEvent.InviteDebug, {
context: 'useLureLinkStatus log',
status,
inviteInfo,
});
// prevent over zealous logging
const statusKey = useMemo(() => {
return `${status}-${fetched}-${checked}`;
}, [status, fetched, checked]);

if (statusKey !== lastLoggedStatus) {
if (status === 'error') {
lureLogger.trackEvent(AnalyticsEvent.InviteError, {
context: 'useLureLinkStatus has error status',
inviteInfo,
});
} else {
lureLogger.trackEvent(AnalyticsEvent.InviteDebug, {
context: 'useLureLinkStatus log',
status,
inviteInfo,
});
}
setLastLoggedStatus(statusKey);
}

return { status, shareUrl: deepLinkUrl, toggle, describe };
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/components/InviteFriendsToTlonButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function InviteFriendsToTlonButton({
linkIsDisabled || status === 'error' || status === 'unsupported';

useEffect(() => {
// eslint-disable-next-line
logger.trackEvent('Invite Button Shown', { group: group?.id });
}, []);

Expand Down

0 comments on commit 7d18ec1

Please sign in to comment.