Skip to content
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
1,795 changes: 216 additions & 1,579 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,11 @@
}
],
"debugVisualizers": [
{
"id": "inlineHexDecoder",
"when": "debugConfigurationType == 'debugpy' && (variableType == 'float' || variableType == 'int')"
}
]
{
"id": "inlineHexDecoder",
"when": "debugConfigurationType == 'debugpy' && (variableType == 'float' || variableType == 'int')"
}
]
},
"extensionDependencies": [
"ms-python.python"
Expand Down Expand Up @@ -561,7 +561,6 @@
"glob": "^8.0.3",
"mocha": "^10.0.0",
"prettier": "^3.0.3",
"rewiremock": "^3.13.0",
"semver": "^7.5.4",
"sinon": "^15.0.2",
"ts-loader": "^9.3.1",
Expand Down
20 changes: 3 additions & 17 deletions src/extension/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

import TelemetryReporter from '@vscode/extension-telemetry';

import { AppinsightsKey, isTestExecution } from '../common/constants';
import { isTestExecution } from '../common/constants';
import { StopWatch } from '../common/utils/stopWatch';
import { ConsoleType, TriggerType } from '../types';
import { DebugConfigurationType } from '../debugger/types';
import { EventName } from './constants';
import { isPromise } from '../common/utils/async';
import { getTelemetryReporter } from './reporter';

/**
* Checks whether telemetry is supported.
Expand All @@ -31,21 +32,6 @@ function isTelemetrySupported(): boolean {
const sharedProperties: Record<string, unknown> = {};

let telemetryReporter: TelemetryReporter | undefined;
function getTelemetryReporter() {
if (!isTestExecution() && telemetryReporter) {
return telemetryReporter;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
const Reporter = require('@vscode/extension-telemetry').default as typeof TelemetryReporter;
telemetryReporter = new Reporter(AppinsightsKey, [
{
lookup: /(errorName|errorMessage|errorStack)/g,
},
]);

return telemetryReporter;
}

export function clearTelemetryReporter(): void {
telemetryReporter = undefined;
Expand All @@ -60,7 +46,7 @@ export function sendTelemetryEvent<P extends IEventNamePropertyMapping, E extend
if (isTestExecution() || !isTelemetrySupported()) {
return;
}
const reporter = getTelemetryReporter();
const reporter = getTelemetryReporter(telemetryReporter);
const measures =
typeof measuresOrDurationMs === 'number'
? { duration: measuresOrDurationMs }
Expand Down
21 changes: 21 additions & 0 deletions src/extension/telemetry/reporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import TelemetryReporter from '@vscode/extension-telemetry';
import { AppinsightsKey, isTestExecution } from '../common/constants';

export function getTelemetryReporter(telemetryReporter: TelemetryReporter | undefined) {
if (!isTestExecution() && telemetryReporter) {
return telemetryReporter;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
const Reporter = require('@vscode/extension-telemetry').default as typeof TelemetryReporter;
telemetryReporter = new Reporter(AppinsightsKey, [
{
lookup: /(errorName|errorMessage|errorStack)/g,
},
]);

return telemetryReporter;
}
18 changes: 10 additions & 8 deletions src/test/unittest/adapter/factory.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import { expect, use } from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as path from 'path';
import * as sinon from 'sinon';
import rewiremock from 'rewiremock';
import { SemVer } from 'semver';
import { instance, mock, when } from 'ts-mockito';
import { DebugAdapterExecutable, DebugAdapterServer, DebugConfiguration, DebugSession, WorkspaceFolder } from 'vscode';
import { IPersistentStateFactory } from '../../../extension/common/types';
import { DebugAdapterDescriptorFactory, debugStateKeys } from '../../../extension/debugger/adapter/factory';
import { IDebugAdapterDescriptorFactory } from '../../../extension/debugger/types';
import { clearTelemetryReporter } from '../../../extension/telemetry';
import { EventName } from '../../../extension/telemetry/constants';
import { PersistentState, PersistentStateFactory } from '../../../extension/common/persistentState';
import * as vscodeApi from '../../../extension/common/vscodeapi';
import { EXTENSION_ROOT_DIR } from '../../../extension/common/constants';
import { Architecture } from '../../../extension/common/platform';
import * as pythonApi from '../../../extension/common/python';
import * as telemetry from '../../../extension/telemetry';
import * as telemetryReporter from '../../../extension/telemetry/reporter';
import * as vscodeApi from '../../../extension/common/vscodeapi';
import { DebugConfigStrings } from '../../../extension/common/utils/localize';

use(chaiAsPromised);
Expand All @@ -36,6 +36,8 @@ suite('Debugging - Adapter Factory', () => {
let getInterpretersStub: sinon.SinonStub;
let getInterpreterDetailsStub: sinon.SinonStub;
let hasInterpretersStub: sinon.SinonStub;
let getTelemetryReporterStub: sinon.SinonStub;
let reporter: any;

const nodeExecutable = undefined;
const debugAdapterPath = path.join(EXTENSION_ROOT_DIR, 'bundled', 'libs', 'debugpy', 'adapter');
Expand Down Expand Up @@ -65,22 +67,23 @@ suite('Debugging - Adapter Factory', () => {
setup(() => {
process.env.VSC_PYTHON_UNIT_TEST = undefined;
process.env.VSC_PYTHON_CI_TEST = undefined;
rewiremock.enable();
rewiremock('@vscode/extension-telemetry').with({ default: Reporter });
reporter = new Reporter();

stateFactory = mock(PersistentStateFactory);
state = mock(PersistentState) as PersistentState<boolean | undefined>;
showErrorMessageStub = sinon.stub(vscodeApi, 'showErrorMessage');
resolveEnvironmentStub = sinon.stub(pythonApi, 'resolveEnvironment');
getInterpretersStub = sinon.stub(pythonApi, 'getInterpreters');
getInterpreterDetailsStub = sinon.stub(pythonApi, 'getInterpreterDetails');
hasInterpretersStub = sinon.stub(pythonApi, 'hasInterpreters');
getTelemetryReporterStub = sinon.stub(telemetryReporter, 'getTelemetryReporter');

when(
stateFactory.createGlobalPersistentState<boolean | undefined>(debugStateKeys.doNotShowAgain, false),
).thenReturn(instance(state));

getInterpretersStub.returns([interpreter]);
hasInterpretersStub.returns(true);
getTelemetryReporterStub.returns(reporter);
factory = new DebugAdapterDescriptorFactory(instance(stateFactory));
});

Expand All @@ -90,8 +93,7 @@ suite('Debugging - Adapter Factory', () => {
Reporter.properties = [];
Reporter.eventNames = [];
Reporter.measures = [];
rewiremock.disable();
clearTelemetryReporter();
telemetry.clearTelemetryReporter();
sinon.restore();
});

Expand Down
2 changes: 2 additions & 0 deletions src/test/unittest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export function run(): Promise<void> {
if ((Reflect as any).metadata === undefined) {
require('reflect-metadata');
}

process.env.VSC_PYTHON_UNIT_TEST = '1';
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
],
"rootDir": "src",
"strict": true, /* enable all strict type-checking options */
"types": [
"chai-as-promised"
],
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
Expand Down