Snapshots in the VSCode plugin¶
A snapshot is a virtual breakpoint that doesn't block your code from running. Unlike traditional breakpoint, snapshots collect the stack trace and variables without interrupting the application at all.
Once you've added a snapshot, you can view the output directly from the IDE.
To use the plugin, make sure you have:
- Attached an agent to your application
- Installed the plugin in your local VSCode instance
- Authenticated the VSCode plugin against your Lightrun account
- The source code file for your running application is opened in VSCode
To add snapshots, you must open the Insert a Snapshot and enter values for snapshot parameters.
Opening the Insert a Snapshot form¶
Select either of the following methods:
A. Through either the Agents or Tags tab
B. From a code line in the VSCode editor
A. Agents or Tags method:
- From either the Agents or Tags tab, select an agent or tag and click the Add Action icon .
The ACTIONS and METRICS menu opens.
- Under ACTIONS, select Snapshot.
The Insert a Snapshot form opens.
B. Code line method:
- Go to the line in your application source code where you want to insert the snapshot.
- Right-click to open the VSCode context menu.
- From the VSCode context menu, click Lightrun....
The VSCode Command Palette opens with a list of Lightrun plugin options.
- From the Command Palette, select Insert a Snapshot.
The Insert a Snapshot form opens.
Entering Snapshot parameters¶
In the Insert a Snapshot form, complete the fields, as follows:
From the available options in the dropdown list, bind the action to a specific agent or tag.
FILENAME & LINE
The source code file into which you're inserting the action. The default path is to the source code file from which you're currently working.
Clicking the Get filename & line icon automatically loads the file name and line number at which the cursor currently is positioned within the VSCode editor.
Use the up/down arrows to change the line number for inserting the snapshot.
The condition of an
ifstatement, used to limit the execution of the action.
myVar % 7 == 0limits the action (log, snapshot, metric) output so that it only prints for variables that are divisible by 7.
- HIT LIMIT
The maximum number of times the snapshot should be taken during the lifetime of the action; default = 1.
The time after which the action ceases to track code behavior and is automatically disabled; default = 1 hour.
- WATCH EXPRESSIONS
Variables or method results to be displayed in the snapshot stack trace. Click + to add additional watch expressions. An expression that you define to be monitored as part of the snapshot. You can evaluate complex expressions, such as methods.
Click Create to add the snapshot.
Upon snapshot creation:
- In the editor area, the icon appears next to the selected code line.
- In the Lightrun plugin, either the Tags or Agents tab opens and the requested agent or tag is expanded, with the Snapshot action appearing below it.
Viewing Snapshot data¶
After you add a snapshot to your code, and a snapshot hit is captured:
- A notification that a snapshot was captured appears in the on the bottom right edge of the VSCode screen.
- The snapshot variables and stack trace appear under the Snapshots tab in the Lightrun plugin.
To view Snapshot variables and stack traces:
To open a snapshot, use either option A or B:
Option A - From either the Agents, Tags, and from the list, select the relevant snapshot.
Option B - Open the Snapshots tab and, from the list, select the relevant snapshot.
The snapshot view window opens in the Snapshots tab.
To expand the snapshot data view, click the (>) icons, next to Variables and Call Stack.
- To view snapshot hits within a series, click the ← and → arrows to cycle through the series or enter a snapshot hit number in the Go to hit box and click Go.
- To view details of a specific frame within a snapshot hit, in the Call Stack pane, click on the relevant stack trace variable or method. In the example below, the add method is selected, and the relevant variable values displayed.
Viewing snapshots from the Lightrun Management Portal is described here.
Viewing and editing a Snapshot configuration¶
After you have created a snapshot, you can view and edit its configuration.
- In the Lightrun plugin, depending on the target, select either the Agents or Tags tab.
- Next to the Snapshot entry, click the Snapshot Options menu icon (...) and select Details.
The Snapshot details window opens.
- To edit the configuration, click the edit icon .
The Edit a Snapshot form opens.
- In the respective fields, enter new values for line number, condition, hit limit, and so on.