Skip to content

Commit

Permalink
upgrade telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
Almenon committed Nov 15, 2024
1 parent 06b0465 commit d6fbf46
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 258 deletions.
1 change: 1 addition & 0 deletions media/connection_string.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
InstrumentationKey=84e1a8aa-bf7d-49d3-82ee-cec803dac0e7;IngestionEndpoint=https://westus2-2.in.applicationinsights.azure.com/;LiveEndpoint=https://westus2.livediagnostics.monitor.azure.com/;ApplicationId=66562322-f74e-478d-89ba-225591963aed
457 changes: 253 additions & 204 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@
"vscode-uri": "^2.1.2"
},
"dependencies": {
"arepl-backend": "^3.0.2",
"vscode-extension-telemetry": "0.1.2"
"@vscode/extension-telemetry": "^0.9.7",
"arepl-backend": "^3.0.2"
},
"bugs": {
"url": "https://github.com/almenon/arepl-vscode-wordcount/issues",
Expand Down
26 changes: 0 additions & 26 deletions src/env/platform/platformService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,19 @@
'use strict';

import * as os from 'os';
import { coerce, SemVer } from 'semver';
import { getOSType, OSType } from '../utils/platform';
import { parseVersion } from '../utils/version';
import { NON_WINDOWS_PATH_VARIABLE_NAME, WINDOWS_PATH_VARIABLE_NAME } from './constants';
import { IPlatformService } from './types';

export class PlatformService implements IPlatformService {
public readonly osType: OSType = getOSType();
public version?: SemVer;
constructor() {}
public get pathVariableName() {
return this.isWindows ? WINDOWS_PATH_VARIABLE_NAME : NON_WINDOWS_PATH_VARIABLE_NAME;
}
public get virtualEnvBinName() {
return this.isWindows ? 'Scripts' : 'bin';
}
public async getVersion(): Promise<SemVer> {
if (this.version) {
return this.version;
}
switch (this.osType) {
case OSType.Windows:
case OSType.OSX:
// Release section of https://en.wikipedia.org/wiki/MacOS_Sierra.
// Version 10.12 maps to Darwin 16.0.0.
// Using os.relase() we get the darwin release #.
try {
const ver = coerce(os.release());
if (ver) {
return this.version = ver;
}
throw new Error('Unable to parse version');
} catch (ex) {
return parseVersion(os.release());
}
default:
throw new Error('Not Supported');
}
}

public get isWindows(): boolean {
return this.osType === OSType.Windows;
Expand Down
2 changes: 0 additions & 2 deletions src/env/platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

import * as fs from 'fs';
import { SemVer } from 'semver';
import { Disposable } from 'vscode';
import { Architecture, OSType } from '../utils/platform';

Expand All @@ -27,7 +26,6 @@ export interface IPlatformService {
readonly isMac: boolean;
readonly isLinux: boolean;
readonly is64bit: boolean;
getVersion(): Promise<SemVer>;
}

export type TemporaryFile = { filePath: string } & Disposable;
Expand Down
18 changes: 0 additions & 18 deletions src/env/utils/version.ts

This file was deleted.

13 changes: 7 additions & 6 deletions src/telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extensions, WorkspaceConfiguration } from "vscode";
import TelemetryReporter from "vscode-extension-telemetry";
import TelemetryReporter from '@vscode/extension-telemetry';
import { userInfo } from "os";
import { join, sep } from "path";
import areplUtils from "./areplUtilities";
Expand All @@ -20,17 +20,17 @@ export default class Reporter{
const extension = extensions.getExtension(extensionId)!;
const extensionVersion = extension.packageJSON.version;

let instrumentation_key = ''
let connection_string = ''
try {
instrumentation_key = readFileSync(join(extension.extensionPath, "media", 'instrumentation_key.txt')).toString()
connection_string = readFileSync(join(extension.extensionPath, "media", 'connection_string.txt')).toString()
} catch (error) {
console.warn('no instrumentation key for AREPL found - disabling telemetry')
console.warn('no connection string for AREPL found - disabling telemetry')
this.enabled = false;
// TelemetryReporter raises error if falsy key so we need to escape before we hit it
return
}

this.reporter = new TelemetryReporter(extensionId, extensionVersion, instrumentation_key);
this.reporter = new TelemetryReporter(connection_string);
this.resetMeasurements()
}

Expand All @@ -43,9 +43,10 @@ export default class Reporter{
// no point in sending same error twice (and we want to stay under free API limit)
if(error.stack == this.lastStackTrace) return

this.reporter.sendTelemetryException(error, {
this.reporter.sendTelemetryErrorEvent(error.name, {
code: code.toString(),
category,
stacktrace: error.stack
})

this.lastStackTrace = error.stack
Expand Down

0 comments on commit d6fbf46

Please sign in to comment.