Skip to content

Commit

Permalink
[Discover] Add tracking for Surrounding Docs page too
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Sep 26, 2024
1 parent 8c305b9 commit b766fcc
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/plugins/discover/public/application/context/context_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export const ContextApp = ({ dataView, anchorId, referrer }: ContextAppProps) =>
navigation,
filterManager,
core,
ebtManager,
fieldsMetadata,
} = services;

const isLegacy = useMemo(() => uiSettings.get(DOC_TABLE_LEGACY), [uiSettings]);
Expand Down Expand Up @@ -199,15 +201,36 @@ export const ContextApp = ({ dataView, anchorId, referrer }: ContextAppProps) =>
);

const addFilter = useCallback(
async (field: DataViewField | string, values: unknown, operation: string) => {
async (field: DataViewField | string, values: unknown, operation: '+' | '-') => {
const newFilters = generateFilters(filterManager, field, values, operation, dataView);
filterManager.addFilters(newFilters);
if (dataViews) {
const fieldName = typeof field === 'string' ? field : field.name;
await popularizeField(dataView, fieldName, dataViews, capabilities);
void ebtManager.trackFilterAddition({
fieldName: fieldName === '_exists_' ? String(values) : fieldName,
filterOperation: fieldName === '_exists_' ? '_exists_' : operation,
fieldsMetadata,
});
}
},
[filterManager, dataViews, dataView, capabilities]
[filterManager, dataViews, dataView, capabilities, ebtManager, fieldsMetadata]
);

const onAddColumnWithTracking = useCallback(
(columnName: string) => {
onAddColumn(columnName);
void ebtManager.trackDataTableSelection({ fieldName: columnName, fieldsMetadata });
},
[onAddColumn, ebtManager, fieldsMetadata]
);

const onRemoveColumnWithTracking = useCallback(
(columnName: string) => {
onRemoveColumn(columnName);
void ebtManager.trackDataTableRemoval({ fieldName: columnName, fieldsMetadata });
},
[onRemoveColumn, ebtManager, fieldsMetadata]
);

const TopNavMenu = navigation.ui.AggregateQueryTopNavMenu;
Expand Down Expand Up @@ -271,8 +294,8 @@ export const ContextApp = ({ dataView, anchorId, referrer }: ContextAppProps) =>
isLegacy={isLegacy}
columns={columns}
grid={appState.grid}
onAddColumn={onAddColumn}
onRemoveColumn={onRemoveColumn}
onAddColumn={onAddColumnWithTracking}
onRemoveColumn={onRemoveColumnWithTracking}
onSetColumns={onSetColumns}
predecessorCount={appState.predecessorCount}
successorCount={appState.successorCount}
Expand Down
58 changes: 58 additions & 0 deletions test/functional/apps/discover/context_awareness/_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,64 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
filterOperation: '-',
});
});

it('should track field usage on surrounding documents page', async () => {
await dataViews.switchToAndValidate('my-example-logs');
await discover.waitUntilSearchingHasFinished();
await unifiedFieldList.waitUntilSidebarHasLoaded();

await dataGrid.clickRowToggle({ rowIndex: 1 });
await discover.isShowingDocViewer();

const [, surroundingActionEl] = await dataGrid.getRowActions();
await surroundingActionEl.click();
await header.waitUntilLoadingHasFinished();
await ebtUIHelper.setOptIn(true);

await dataGrid.clickRowToggle({ rowIndex: 0 });
await discover.isShowingDocViewer();

// event 1
await dataGrid.clickFieldActionInFlyout('service.name', 'toggleColumnButton');
await header.waitUntilLoadingHasFinished();
await discover.waitUntilSearchingHasFinished();

// event 2
await dataGrid.clickFieldActionInFlyout('log.level', 'toggleColumnButton');
await header.waitUntilLoadingHasFinished();
await discover.waitUntilSearchingHasFinished();

// event 3
await dataGrid.clickFieldActionInFlyout('log.level', 'addFilterOutValueButton');
await header.waitUntilLoadingHasFinished();
await discover.waitUntilSearchingHasFinished();

const [event1, event2, event3] = await ebtUIHelper.getEvents(Number.MAX_SAFE_INTEGER, {
eventTypes: ['discover_field_usage'],
withTimeoutMs: 500,
});

expect(event1.properties).to.eql({
eventName: 'dataTableSelection',
fieldName: 'service.name',
});

expect(event2.properties).to.eql({
eventName: 'dataTableRemoval',
fieldName: 'log.level',
});

expect(event3.properties).to.eql({
eventName: 'filterAddition',
fieldName: 'log.level',
filterOperation: '-',
});

expect(event3.context.discoverProfiles).to.eql([
'example-root-profile',
'example-data-source-profile',
]);
});
});
});
}

0 comments on commit b766fcc

Please sign in to comment.