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

[2.3.x] Turf most tracking in jupyter extension #8213

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,52 +56,6 @@ describe('telemetry plugin', () => {
);
});

it('should track app commands', async () => {
await telemetry.activate(app);
app.commands.addCommand('fake:command', {execute: jest.fn()});
await app.commands.execute('fake:command', {fake: 'args'});

expect(track).toHaveBeenCalledWith('command', {
id: 'fake:command',
args: {fake: 'args'},
});
});

it('should track notebook commands with a prompt', async () => {
await telemetry.activate(app);

expect(track).toHaveBeenCalledWith('command', {
id: 'notebook:action:executed',
args: {
action: 'pachctl version',
},
});
});

it('should track notebook commands without a prompt', async () => {
getNotebookAction.mockImplementation(() => ({
cell: {
inputArea: {
node: {
innerText: 'Hello Telemetry',
},
},
promptNode: {
innerText: '',
},
},
}));

await telemetry.activate(app);

expect(track).toHaveBeenCalledWith('command', {
id: 'notebook:action:executed',
args: {
action: 'Hello Telemetry',
},
});
});

it('should track clicks', () => {
const {getByTestId, getByText} = render(
<>
Expand Down
42 changes: 0 additions & 42 deletions jupyter-extension/src/plugins/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,9 @@
import {JupyterFrontEnd} from '@jupyterlab/application';
import {NotebookActions} from '@jupyterlab/notebook';
import debounce from 'lodash/debounce';
import {load, track} from 'rudder-sdk-js';

export const CLICK_TIMEOUT = 500;

/**
* TODO: This captures a lot of events. Some we might want to filter out.
* Some events don't get captured if clicked from top level menus.
* We'll need to figure out if menu command tracking is different,
* or maybe even add custom tracking for them.
*/
const initCommandTracking = (app: JupyterFrontEnd): void => {
app.commands.commandExecuted.connect((_, command) => {
track('command', {
id: command.id,
// We have to copy the args to a plain object
args: JSON.parse(JSON.stringify(command.args)),
});
});
};

const initNotebookTracking = () => {
NotebookActions.executed.connect((_, action) => {
// This transforms '[1]: pachctl version' to 'pachctl version'
const promptText = action.cell.promptNode.innerText;
const actionText = action.cell.inputArea.node.innerText.replace(
promptText ? promptText + '\n' : '',
'',
);

track('command', {
id: 'notebook:action:executed',
args: {
action: actionText,
},
});
});
};

const initTerminalTracking = () => {
// TODO: what info do we want to track from a terminal?
};

const handleClick = debounce(
(evt: Event) => {
const element = evt.target as HTMLElement;
Expand Down Expand Up @@ -72,8 +33,5 @@ export const init = (app: JupyterFrontEnd): void => {
'20C6D2xFLRmyFTqtvYDEgNfwcRG',
'https://pachyderm-dataplane.rudderstack.com',
);
initCommandTracking(app);
initNotebookTracking();
initTerminalTracking();
initClickTracking();
};