Skip to content

Collecting data for an investigation.

Kacie Kang edited this page Apr 2, 2025 · 15 revisions

Collecting Trace Logs

  1. Enable trace logging by adding "python.analysis.logLevel": "Trace" to your settings.json configuration file.
  2. Select "View: Toggle Output" from the command palette (Ctrl+Shift+P on Windows/Linux, Command+Shift+P on macOS), then select "Python Language Server" in the dropdown on the right.
  3. Copy the entire log starting with "Pylance language server XXX (pyright xxx) starting"

The output will be substantial, but having the full log will help people investigating what is happening

  • You can confirm you have the correct log by checking for entries such as the one below.
Search paths for file:///c%3A/repo/test
  c:\repo\test
  c:\repo\test\src
  c:\repo\test\.venv
  c:\repo\test\.venv\Lib\site-packages
  
Adding fs watcher for library directories:
  file:///c%3A/repo/test/.venv
  file:///c%3A/repo/test/.venv/Lib/site-packages
  
Adding fs watcher for directories:
  file:///c%3A/repo/test

Collecting Trace Logs Using Commands

You can also save the log by using the Pylance: Start Logging and Pylance: Stop Logging commands. Simply start logging, perform your repro, stop logging, and then share the saved log file with us.

Automatic Log Upload Using Report Issue Command

[available in 2025.4.1 and after]

When you encounter an issue with Pylance and need to report it, the extension can automatically upload your logs to GitHub. Here’s how the process works:

  1. Add "python.analysis.logLevel": "Trace" to your settings.json configuration file.
  • Ensure trace logging is enabled before proceeding with reproduction.
  1. Select "Pylance: Report Issue" from the command palette (Ctrl+Shift+P on Windows/Linux, Command+Shift+P on macOS).
  • If the log size exceeds issue size limit(65K), Pylance will prompt you for consent to upload the log as a blob to GitHub.

You will see a message asking for consent or a decline.
If you consent, Pylance will upload the log to a GitHub blob and attach the SHA of the log to the issue. How to retrieve logs from a blob?
If you decline, the log will be truncated and shown in the issue reporter board.

  1. Fill in the required repro steps, then click Create on Github button

Collecting type evaluation related data in the log

  1. set python.analysis.logLevel to Trace
  2. set python.analysis.logTypeEvaluationTime to true
  3. set python.analysis.typeEvaluationTimeThreshold to 500

this will include type evaluation related data to the log. this data is quite large so it should be only included when needed.

Collecting *.cpuprofiles

[available in 2024.3.100 and after]

  1. Load the Pylance extension by either creating/opening a Python file or folder.
  2. Select "View: Toggle Output" from the command palette (Ctrl+Shift+P on Windows/Linux, Command+Shift+P on macOS), and wait for the "Python Language Server" output pane to be created, logging the state "Pylance language server XXX (pyright xxx) starting".

image

  1. Wait for VS Code to go idle (no CPU time on VS Code).
  2. Select "Pylance: Start profiling" from the command palette.
  3. Reproduce the performance issue.
  • when reproducing, please ensure it's as short as possible, containing only the performance issue observed, to avoid unnecessary noise and make identifying issues easier, if not impossible.
  1. Wait for VS Code to go idle (no CPU time on VS Code).
  2. Select "Pylance: Stop profiling" from the command palette.
  3. Go to the folder the message box showed.

image

  1. Select all *.cpuprofile files in the folder.
  2. Provide those files to Pylance, such as attaching them to an issue.
  • If you believe it is an indexing issue, one should:
  1. Start pylance extension with "python.analysis.indexing": false and
  2. Then perform steps 1~4, change "python.analysis.indexing": true in settings.json and save.
  3. Then perform steps 6~10.
  • "Pylance: Stop profiling" will generate cpuprofile files for each worker thread. Having all of them will help those investigating the performance issue.

  • If you encounter an Out of Memory (OOM) error because the reproduction step is too large, use "python.analysis.nodeExecutable" to allocate more memory to the Pylance extension.

How to retrieve logs from a blob?

This guide explains how to use a SHA value to form a GET request to the GitHub API, retrieve the "content" field, and decode it.

1. Identify the SHA:

  • Example SHA: 99787ed45a7080781306fb8204913ca2c5c46f17

2. Form the GET Request:

  • Replace {sha} with the appropriate values.
  • GET https://api.github.com/repos/microsoft/pylance-release/git/blobs/{sha} HTTP/1.1
  • No Authorization is needed

3. Use a tool like curl, Postman, or VS Code's REST Client extension to send the GET request.

  • The response will include a JSON object with a content field
{
  "sha": "99787ed45a7080781306fb8204913ca2c5c46f17",
  "node_id": "MDQ6QmxvYjI2NTkwMjYyNTo5OTc4N2VkNDVhNzA4MDc4MTMwNmZiODIwNDkxM2NhMmM1YzQ2ZjE3",
  "size": 179617,
  "url": "https://api.github.com/repos/microsoft/pylance-release/git/blobs/99787ed45a7080781306fb8204913ca2c5c46f17",
  "content": THISISENCODEDSTRING
}

4. Decode the Content:

The content field is Base64-encoded. Here is a python script to decode it. or ask your favoriate AI to do so :)

import base64

# Base64 encoded string
encoded_string = """THISISENCODEDSTRING"""
# Decode the base64 string
decoded_bytes = base64.b64decode(encoded_string + '==')
decoded_string = decoded_bytes.decode('utf-8')

print(decoded_string)

Clone this wiki locally