Skip to content

Commit

Permalink
fix: interactions now send array of paths
Browse files Browse the repository at this point in the history
  • Loading branch information
NisargIO committed Dec 12, 2024
1 parent d9cd5c2 commit a454649
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/scan/src/core/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ export interface MonitoringProps {
branch?: string | null;
}

export interface MonitoringWithoutRouteProps
extends Omit<MonitoringProps, 'route' | 'path'> {}
export type MonitoringWithoutRouteProps = Omit<
MonitoringProps,
'route' | 'path'
>;

export const Monitoring = ({
url,
Expand Down
3 changes: 2 additions & 1 deletion packages/scan/src/core/monitor/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getSession } from './utils';
import type { Interaction, IngestRequest, InternalInteraction } from './types';

const getInteractionId = (interaction: InternalInteraction) =>
`${interaction.performanceEntry.type}::${interaction.componentPath}::${interaction.url}`;
`${interaction.performanceEntry.type}::<REPLACED_PATH>::${interaction.url}`; // We replace the path with <REPLACED_PATH> in production

const INTERACTION_TIME_TILL_COMPLETED = 4000;

Expand Down Expand Up @@ -71,6 +71,7 @@ const toPayloadInteraction = (interactions: Array<InternalInteraction>) =>
(interaction) =>
({
id: getInteractionId(interaction),
path: interaction.componentPath,
name: interaction.componentName,
time: interaction.performanceEntry.duration,
timestamp: interaction.performanceEntry.timestamp,
Expand Down
9 changes: 4 additions & 5 deletions packages/scan/src/core/monitor/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ const isMinified = (name: string): boolean => {
export function getInteractionPath(
fiber: Fiber | null,
filters: PathFilters = DEFAULT_FILTERS,
): string {
if (!fiber) return '';
): Array<string> {
if (!fiber) return [];

const fullPath: Array<string> = [];

Expand All @@ -119,8 +119,7 @@ export function getInteractionPath(
current = current.return;
}

const normalized = normalizePath(fullPath);
return normalized;
return fullPath;
}

let currentMouseOver: Element;
Expand All @@ -132,7 +131,7 @@ function getCleanComponentName(component: any): string {
return name.replace(/^(Memo|Forward(Ref)?|With.*?)\((.*?)\)$/, '$3');
}

function normalizePath(path: Array<string>): string {
export function normalizePath(path: Array<string>): string {
const cleaned = path.filter(Boolean);

const deduped = cleaned.filter((name, i) => name !== cleaned[i - 1]);
Expand Down
3 changes: 2 additions & 1 deletion packages/scan/src/core/monitor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Session {

export interface Interaction {
id: string; // a hashed unique id for interaction (groupable across sessions)
path: Array<string>; // the path of the interaction
name: string; // name of interaction (i.e nav#top-menu.sc-601d0142-19.gHiJkL) or something useful
type: string; // type of interaction i.e pointer
time: number; // time of interaction in ms
Expand Down Expand Up @@ -63,7 +64,7 @@ export interface InternalInteraction {
commit: string | null;
branch: string | null;
uniqueInteractionId: string;
componentPath: string;
componentPath: Array<string>;
performanceEntry: PerformanceInteraction;
components: Map<string, InternalComponentCollection>;
}
Expand Down

0 comments on commit a454649

Please sign in to comment.