Skip to content

Commit

Permalink
Add debug and error telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Auchenberg committed Apr 11, 2020
1 parent 9d7c203 commit 50356bb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
7 changes: 5 additions & 2 deletions ext-src/BrowserViewWindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import * as EventEmitter from 'eventemitter2';
import Browser from './browser';
import { ExtensionConfiguration } from './extensionConfiguration';
import { BrowserViewWindow } from './BrowserViewWindow';
import { Telemetry } from './telemetry';

export class BrowserViewWindowManager extends EventEmitter.EventEmitter2 {
public openWindows: Set<BrowserViewWindow>;
private browser: any;
private defaultConfig: ExtensionConfiguration;
private telemetry: Telemetry;

constructor(extensionPath: string) {
constructor(extensionPath: string, telemetry: Telemetry) {
super();
this.openWindows = new Set();
this.telemetry = telemetry;
this.defaultConfig = {
extensionPath: extensionPath,
startUrl: 'http://code.visualstudio.com',
Expand Down Expand Up @@ -62,7 +65,7 @@ export class BrowserViewWindowManager extends EventEmitter.EventEmitter2 {
let config = { ...this.defaultConfig };

if (!this.browser) {
this.browser = new Browser(config);
this.browser = new Browser(config, this.telemetry);
}

let lastColumnNumber = this.getLastColumnNumber();
Expand Down
9 changes: 8 additions & 1 deletion ext-src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import * as whichChrome from 'which-chrome';
import * as vscode from 'vscode';
import * as os from 'os';
import { ExtensionConfiguration } from './extensionConfiguration';
import { Telemetry } from './telemetry';

const puppeteer = require('puppeteer-core');
const getPort = require('get-port');

export default class Browser extends EventEmitter {
private browser: any;
private telemetry: Telemetry;
public remoteDebugPort: number = 0;

constructor(private config: ExtensionConfiguration) {
constructor(private config: ExtensionConfiguration, telemetry: Telemetry) {
super();
this.telemetry = telemetry;
}

private async launchBrowser() {
Expand All @@ -32,6 +35,10 @@ export default class Browser extends EventEmitter {
chromeArgs.push(`--remote-debugging-port=${this.remoteDebugPort}`);

if (!chromePath) {
this.telemetry.sendEvent('error', {
type: 'chromeNotFound'
});

throw new Error(
`No Chrome installation found, or no Chrome executable set in the settings - used path ${chromePath}`
);
Expand Down
11 changes: 10 additions & 1 deletion ext-src/debugProvider.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { env } from 'vscode';
import * as path from 'path';
import * as vscode from 'vscode';
import { Telemetry } from './telemetry';

export default class DebugProvider {
private windowManager: any;
private telemetry: Telemetry;

constructor(windowManager: any) {
constructor(windowManager: any, telemetry: Telemetry) {
this.windowManager = windowManager;
this.telemetry = telemetry;

vscode.debug.onDidTerminateDebugSession((e: vscode.DebugSession) => {
if (e.name === `Browser Preview: Launch` && e.configuration.urlFilter) {
Expand All @@ -18,6 +21,7 @@ export default class DebugProvider {

getProvider(): vscode.DebugConfigurationProvider {
let manager = this.windowManager;
let telemetry = this.telemetry;

return {
provideDebugConfigurations(
Expand Down Expand Up @@ -57,9 +61,14 @@ export default class DebugProvider {
};

if (config && config.type === 'browser-preview') {
telemetry.sendEvent('openDebug', {
type: config.request
});

if (config.request && config.request === `attach`) {
debugConfig.name = `Browser Preview: Attach`;
debugConfig.port = manager.getDebugPort();

if (debugConfig.port === null) {
vscode.window.showErrorMessage(
'No Browser Preview window was found. Open a Browser Preview window or use the "launch" request type.'
Expand Down
7 changes: 4 additions & 3 deletions ext-src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { setupLiveShare } from './live-share';
import { Telemetry } from './telemetry';

export function activate(context: vscode.ExtensionContext) {
const windowManager = new BrowserViewWindowManager(context.extensionPath);
const debugProvider = new DebugProvider(windowManager);

const telemetry = new Telemetry();

const windowManager = new BrowserViewWindowManager(context.extensionPath, telemetry);
const debugProvider = new DebugProvider(windowManager, telemetry);

telemetry.sendEvent('activate');

vscode.window.registerTreeDataProvider('targetTree', new TargetTreeProvider());
Expand Down

0 comments on commit 50356bb

Please sign in to comment.