Skip to content

Telemetry #394

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

Merged
merged 3 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"watch": "tsc -watch -p ./"
},
"dependencies": {
"@sentry/node": "^5.19.2",
"@types/assert": "^1.5.1",
"@types/jest": "^26.0.4",
"@types/jsdom": "^16.2.3",
Expand All @@ -52,7 +51,8 @@
"node-fetch": "^2.6.0",
"semver": "^7.3.2",
"ts-jest": "^26.1.3",
"typescript": "^3.9.7"
"typescript": "^3.9.7",
"vscode-extension-telemetry": "^0.1.6"
},
"devDependencies": {
"eslint-config-prettier": "^6.11.0",
Expand Down
2 changes: 1 addition & 1 deletion src/actions/setupActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as git from '../services/git'
import loadWatchers from './utils/loadWatchers'
import openFiles from './utils/openFiles'
import runCommands from './utils/runCommands'
import onError from '../services/sentry/onError'
import { onError } from '../services/telemetry'
import logger from '../services/logger'

interface SetupActions {
Expand Down
7 changes: 7 additions & 0 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { exec } from '../services/node'
import { WORKSPACE_ROOT, TUTORIAL_URL } from '../environment'
import reset from '../services/reset'
import getLastCommitHash from '../services/reset/lastHash'
import { onEvent } from '../services/telemetry'

const readFileAsync = promisify(readFile)

Expand Down Expand Up @@ -128,6 +129,12 @@ class Channel implements Channel {
try {
const data: TT.Tutorial = action.payload.tutorial

onEvent('tutorial_start', {
tutorial_id: data.id,
tutorial_version: data.version,
tutorial_title: data.summary.title,
})

// validate extension version
const expectedAppVersion = data.config?.appVersions?.vscode
if (expectedAppVersion) {
Expand Down
11 changes: 10 additions & 1 deletion src/editor/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode'
import { createCommands } from './commands'
import * as telemetry from '../services/telemetry'

class Editor {
// extension context set on activation
Expand All @@ -22,17 +23,25 @@ class Editor {
workspaceState: this.vscodeExt.workspaceState,
})

const subscribe = (sub: any) => {
this.vscodeExt.subscriptions.push(sub)
}

// register commands
for (const cmd in commands) {
const command: vscode.Disposable = vscode.commands.registerCommand(cmd, commands[cmd])
this.vscodeExt.subscriptions.push(command)
subscribe(command)
}

telemetry.activate(subscribe)
}
public deactivate = (): void => {
// cleanup subscriptions/tasks
for (const disposable of this.vscodeExt.subscriptions) {
disposable.dispose()
}

telemetry.deactivate()
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { getWorkspaceRoot } from './services/workspace'
import * as os from 'os'

// CodeRoad version
export const VERSION = 'unknown'
export const VERSION = require('../package.json').version

export const EXTENSION_ID = 'coderoad'

// Node env
export type Env = 'test' | 'local' | 'development' | 'production'
// @ts-ignore
export const NODE_ENV: Env = process.env.NODE_ENV || 'production'
export const NODE_ENV: Env = process.env.NODE_ENV || 'development'

// toggle logging in development
export const LOG = false

// error logging tool
export const SENTRY_DSN: string | null = null
export const INSTRUMENTATION_KEY = '6ff37c76-72f3-48e3-a1b9-d5636f519b7b'

// uri path to the users project workspace
export const WORKSPACE_ROOT: string = getWorkspaceRoot()
Expand Down
3 changes: 0 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// init error logging
import './services/sentry/init'

import Editor from './editor'

// vscode editor
Expand Down
11 changes: 0 additions & 11 deletions src/services/sentry/init.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/services/sentry/onError.ts

This file was deleted.

43 changes: 43 additions & 0 deletions src/services/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import TelemetryReporter from 'vscode-extension-telemetry'
import { EXTENSION_ID, VERSION, INSTRUMENTATION_KEY, NODE_ENV } from '../../environment'

/**
* Telemetry
* https://github.com/microsoft/vscode-extension-telemetry
*
*/

interface Properties {
[key: string]: string
}

interface Measurements {
[key: string]: number
}

let reporter: any

export const activate = (subscribeFn: (reporter: any) => void): void => {
if (NODE_ENV === 'production') {
reporter = new TelemetryReporter(EXTENSION_ID, VERSION, INSTRUMENTATION_KEY)
subscribeFn(reporter)
}
}

export const deactivate = (): void => {
if (reporter) {
reporter.dispose()
}
}

export const onError = (error: Error, properties?: Properties, measurements?: Measurements): void => {
if (reporter) {
reporter.sendTelemetryException(error, properties, measurements)
}
}

export const onEvent = (eventName: string, properties?: Properties, measurements?: Measurements): void => {
if (reporter) {
reporter.sendTelemetryEvent(eventName, properties, measurements)
}
}
2 changes: 1 addition & 1 deletion src/services/testRunner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import logger from '../logger'
import parser, { ParserOutput } from './parser'
import parseSubtasks from './subtasks'
import { debounce, throttle } from './throttle'
import onError from '../sentry/onError'
import { onError } from '../telemetry'
import { clearOutput, addOutput } from './output'
import { formatFailOutput } from './formatOutput'

Expand Down
2 changes: 1 addition & 1 deletion src/services/webview/render.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JSDOM } from 'jsdom'
import * as path from 'path'
import * as vscode from 'vscode'
import onError from '../sentry/onError'
import { onError } from '../telemetry'

const getNonce = (): string => {
let text = ''
Expand Down
Loading