Skip to content

Commit

Permalink
Add more logging for debugging to the nightly tests (#7315)
Browse files Browse the repository at this point in the history
* Add more logging for debugging

* Add some more logging

* Add more logging

* Fix linter
  • Loading branch information
rchiodo authored Sep 10, 2019
1 parent abf86f3 commit bb6899c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions build/ci/vscode-python-nightly-flake-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ variables:
MOCHA_FILE: '$(Build.ArtifactStagingDirectory)/test-junit.xml' # All test files will write their JUnit xml output to this file, clobbering the last time it was written.
MOCHA_REPORTER_JUNIT: true # Use the mocha-multi-reporters and send output to both console (spec) and JUnit (mocha-junit-reporter).
VSC_PYTHON_LOG_FILE: '$(Build.ArtifactStagingDirectory)/pvsc.log'
PTVSD_LOG_DIR: '$(Build.ArtifactStagingDirectory)' # Get the debugger to log output too

jobs:

Expand Down
29 changes: 27 additions & 2 deletions src/client/datascience/jupyter/jupyterDebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
// Try to connect to this notebook
const config = await this.connect(notebook);
if (config) {
traceInfo('connected to notebook during debugging');

// First check if this is a live share session. Skip debugging attach on the guest
// tslint:disable-next-line: no-any
const hasRole = (notebook as any) as ILiveShareHasRole;
Expand All @@ -75,6 +77,8 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
const importResults = await this.executeSilently(notebook, `import ptvsd\nptvsd.wait_for_attach()`);
if (importResults.length === 0 || importResults[0].state === CellState.error) {
traceWarning('PTVSD not found in path.');
} else {
this.traceCellResults('import startup', importResults);
}

// Then enable tracing
Expand Down Expand Up @@ -119,6 +123,22 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
}
}

private traceCellResults(prefix: string, results: ICell[]) {
if (results.length > 0 && results[0].data.cell_type === 'code') {
const cell = results[0].data as nbformat.ICodeCell;
const error = cell.outputs[0].evalue;
if (error) {
traceError(`${prefix} Error : ${error}`);
} else {
const data = cell.outputs[0].data;
const text = cell.outputs[0].text;
traceInfo(`${prefix} Output: ${text || JSON.stringify(data)}`);
}
} else {
traceInfo(`${prefix} no output.`);
}
}

private async connect(notebook: INotebook): Promise<DebugConfiguration | undefined> {
// If we already have configuration, we're already attached, don't do it again.
let result = this.configs.get(notebook.resource.toString());
Expand Down Expand Up @@ -201,7 +221,8 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
const ptvsdPathList = this.calculatePtvsdPathList(notebook);

if (ptvsdPathList && ptvsdPathList.length > 0) {
await this.executeSilently(notebook, `import sys\r\nsys.path.extend([${ptvsdPathList}])\r\nsys.path`);
const result = await this.executeSilently(notebook, `import sys\r\nsys.path.extend([${ptvsdPathList}])\r\nsys.path`);
this.traceCellResults('Appending paths', result);
}
}

Expand Down Expand Up @@ -243,6 +264,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {

private parsePtvsdVersionInfo(cells: ICell[]): IPtvsdVersion | undefined {
if (cells.length < 1 || cells[0].state !== CellState.finished) {
this.traceCellResults('parsePtvsdVersionInfo', cells);
return undefined;
}

Expand All @@ -262,6 +284,8 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
}
}

this.traceCellResults('parsingPtvsdVersionInfo', cells);

return undefined;
}

Expand Down Expand Up @@ -292,6 +316,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
private async installPtvsd(notebook: INotebook): Promise<void> {
// tslint:disable-next-line:no-multiline-string
const ptvsdInstallResults = await this.executeSilently(notebook, `import sys\r\n!{sys.executable} -m pip install -U ptvsd`);
traceInfo('Installing ptvsd');

if (ptvsdInstallResults.length > 0) {
const installResultsString = this.extractOutput(ptvsdInstallResults[0]);
Expand All @@ -302,7 +327,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
return;
}
}

this.traceCellResults('Installing PTVSD', ptvsdInstallResults);
sendTelemetryEvent(Telemetry.PtvsdInstallFailed);
traceError('Failed to install ptvsd');
// Failed to install ptvsd, throw to exit debugging
Expand Down

0 comments on commit bb6899c

Please sign in to comment.