Revert "Add telemetry for OpenTerminal success/failure (#192)" (#198)

This reverts commit 83b13de685.
This commit is contained in:
Tanuj Mittal 2020-09-11 23:12:28 -07:00 committed by GitHub
parent 728eeefa17
commit c4257bf4a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 48 deletions

View File

@ -48,31 +48,16 @@ export function sendCachedDataMessage<TResponseDataModel>(
export function sendMessage(data: any): void { export function sendMessage(data: any): void {
if (canSendMessage()) { if (canSendMessage()) {
const dataExplorerWindow = getDataExplorerWindow(); window.parent.postMessage(
if (dataExplorerWindow) { {
dataExplorerWindow.parent.postMessage( signature: "pcIframe",
{ data: data
signature: "pcIframe", },
data: data window.document.referrer
}, );
dataExplorerWindow.document.referrer
);
}
} }
} }
const getDataExplorerWindow = (): Window => {
// Traverse up the window to find a window with `dataExplorerPlatform` property
let dataExplorerWindow: Window = window;
// TODO: Need to `any` here since the window imports Explorer which can't be in strict mode yet
// eslint-disable-next-line @typescript-eslint/no-explicit-any
while (!(dataExplorerWindow as any).dataExplorerPlatform && dataExplorerWindow.parent) {
dataExplorerWindow = dataExplorerWindow.parent;
}
return dataExplorerWindow;
};
export function canSendMessage(): boolean { export function canSendMessage(): boolean {
return window.parent !== window; return window.parent !== window;
} }

View File

@ -70,8 +70,7 @@ export enum Action {
NotebooksGitHubManualRepoAdd, NotebooksGitHubManualRepoAdd,
NotebooksGitHubManageRepo, NotebooksGitHubManageRepo,
NotebooksGitHubCommit, NotebooksGitHubCommit,
NotebooksGitHubDisconnect, NotebooksGitHubDisconnect
OpenTerminal
} }
export const ActionModifiers = { export const ActionModifiers = {

View File

@ -4,8 +4,6 @@ import "@jupyterlab/terminal/style/index.css";
import "./index.css"; import "./index.css";
import { ServerConnection } from "@jupyterlab/services"; import { ServerConnection } from "@jupyterlab/services";
import { JupyterLabAppFactory } from "./JupyterLabAppFactory"; import { JupyterLabAppFactory } from "./JupyterLabAppFactory";
import { Action } from "../Shared/Telemetry/TelemetryConstants";
import * as TelemetryProcessor from "../Shared/Telemetry/TelemetryProcessor";
const getUrlVars = (): { [key: string]: string } => { const getUrlVars = (): { [key: string]: string } => {
const vars: { [key: string]: string } = {}; const vars: { [key: string]: string } = {};
@ -16,7 +14,10 @@ const getUrlVars = (): { [key: string]: string } => {
return vars; return vars;
}; };
const createServerSettings = (urlVars: { [key: string]: string }): ServerConnection.ISettings => { const main = (): void => {
const urlVars = getUrlVars();
console.log("URL parameters", urlVars);
let body: BodyInit; let body: BodyInit;
if (urlVars.hasOwnProperty("terminalEndpoint")) { if (urlVars.hasOwnProperty("terminalEndpoint")) {
body = JSON.stringify({ body = JSON.stringify({
@ -38,29 +39,14 @@ const createServerSettings = (urlVars: { [key: string]: string }): ServerConnect
fetch: window.parent.fetch fetch: window.parent.fetch
}; };
} }
const serverSettings = ServerConnection.makeSettings(options);
return ServerConnection.makeSettings(options); if (urlVars.hasOwnProperty("terminal")) {
}; JupyterLabAppFactory.createTerminalApp(serverSettings);
return;
const main = async (): Promise<void> => {
const urlVars = getUrlVars();
const serverSettings = createServerSettings(urlVars);
const startTime = TelemetryProcessor.traceStart(Action.OpenTerminal, {
baseUrl: serverSettings.baseUrl
});
try {
if (urlVars.hasOwnProperty("terminal")) {
await JupyterLabAppFactory.createTerminalApp(serverSettings);
} else {
throw new Error("Only terminal is supported");
}
TelemetryProcessor.traceSuccess(Action.OpenTerminal, startTime);
} catch (error) {
TelemetryProcessor.traceFailure(Action.OpenTerminal, startTime);
} }
throw new Error("Only terminal is supported");
}; };
window.addEventListener("load", main); window.addEventListener("load", main);