Add telemetry for OpenTerminal success/failure (#192)
* Add telemetry for OpenTerminal success/failure * Address review comments
This commit is contained in:
parent
c401f88aae
commit
83b13de685
|
@ -48,16 +48,31 @@ export function sendCachedDataMessage<TResponseDataModel>(
|
||||||
|
|
||||||
export function sendMessage(data: any): void {
|
export function sendMessage(data: any): void {
|
||||||
if (canSendMessage()) {
|
if (canSendMessage()) {
|
||||||
window.parent.postMessage(
|
const dataExplorerWindow = getDataExplorerWindow();
|
||||||
{
|
if (dataExplorerWindow) {
|
||||||
signature: "pcIframe",
|
dataExplorerWindow.parent.postMessage(
|
||||||
data: data
|
{
|
||||||
},
|
signature: "pcIframe",
|
||||||
window.document.referrer
|
data: data
|
||||||
);
|
},
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,8 @@ export enum Action {
|
||||||
NotebooksGitHubManualRepoAdd,
|
NotebooksGitHubManualRepoAdd,
|
||||||
NotebooksGitHubManageRepo,
|
NotebooksGitHubManageRepo,
|
||||||
NotebooksGitHubCommit,
|
NotebooksGitHubCommit,
|
||||||
NotebooksGitHubDisconnect
|
NotebooksGitHubDisconnect,
|
||||||
|
OpenTerminal
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ActionModifiers = {
|
export const ActionModifiers = {
|
||||||
|
|
|
@ -4,6 +4,8 @@ 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 } = {};
|
||||||
|
@ -14,10 +16,7 @@ const getUrlVars = (): { [key: string]: string } => {
|
||||||
return vars;
|
return vars;
|
||||||
};
|
};
|
||||||
|
|
||||||
const main = (): void => {
|
const createServerSettings = (urlVars: { [key: string]: string }): ServerConnection.ISettings => {
|
||||||
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({
|
||||||
|
@ -39,14 +38,29 @@ const main = (): void => {
|
||||||
fetch: window.parent.fetch
|
fetch: window.parent.fetch
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const serverSettings = ServerConnection.makeSettings(options);
|
|
||||||
|
|
||||||
if (urlVars.hasOwnProperty("terminal")) {
|
return ServerConnection.makeSettings(options);
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue