Skip to content

Work with Lightrun Snapshots in the Visual Studio IDE

Important

The Lightrun extension for Visual Studio, referred to hereafter as the "Lightrun plugin", is in public beta.

A snapshot is a virtual breakpoint that doesn't block your code from running. Unlike traditional breakpoints, snapshots collect the stack trace and variables without interrupting the application at all. To learn more about Lightrun snapshot, see Lightrun Snapshots.

Once you've added a snapshot, you can view the output directly from the IDE.

Prerequisites

To use the plugin, make sure you have:

  1. Attached an agent to your application.
  2. Installed the plugin in your local Visual Studio instance.
  3. Authenticated the Visual Studio plugin against your Lightrun account.
  4. Verfified that the source code file for your running application is opened in Visual Studio.

Add a snapshot

  1. Open the Insert a Snapshot and enter values for snapshot parameters using one of these methods: from the plugin top menu bar or the Agents or Tags tab, or directly from the gutter next to the code line in the Visual Studio editor.

    • Method 1: From the Agents or Tags tab or the top menu in the plugin.

      a. In either the top menu bar or under the Agents or Tags tab, select an agent or tag, then click the Add Action icon.

      Add Action button --icon.

      The **ACTIONS** menu opens.
      

      b. Under ACTIONS, select Snapshot to open the Insert a Snapshot dialog.

      Lightrun context menu --half

    • Method 2: From the code line gutter in the code editor.

      1. Go to the line in your application source code where you want to insert the snapshot. A Plus icon will appear.
      2. Click the icon to open the Visual Studio context menu.
      3. In the menu, click Lightrun... to open the Visual Studio Command Palette with a list of Lightrun plugin options.

        Lightrun plugin command palette --half

      4. From the Command Palette, select Insert a Snapshot.

        The Insert a Snapshot dialog opens.

        Inserting a Snapshot --half

  2. In the Insert a Snapshot dialog, complete the fields, as follows:

    Fields Description
    Source From the available options in the dropdown list, bind the action to a specific agent, tag, or custom source.
    Click the Custom Source icon --icon icon to create a new custom source.
    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.
    Condition The condition of an if statement, used to limit the execution of the action.
    For example, The condition myVar % 7 == 0 limits 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.
    Lifetime The time after which the action ceases to track code behavior and is automatically disabled; default = 1 hour.
    Target Select your preferred action output target. You can pick either:
    - Stdout: Logs are routed only to your application's standard output.
    - Plugin: Logs appear in the Lightrun Console, the Lightrun Management Portal, and configured integrations.
    or both options at once.
    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.
  3. Click Create to add the snapshot.

    Upon snapshot creation:

    • In the editor area, the Snapshot icon 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.

View snapshot data

After you add a snapshot to your code and a snapshot hit is captured:

  • A notification appears at the bottom right of the Visual Studio IDE, indicating that a snapshot was captured.
  • The snapshot variables and stack trace appear under the Snapshots Hits tab in the Lightrun plugin.

To view Snapshot variables and stack traces:

  1. To open a snapshot, use either of the following methods:

    • From either the Agents, Tags, or from the Actions list, select the relevant snapshot.
    • Open the Snapshots tab and, from the list, select the relevant snapshot.

    The snapshot view window opens in the Snapshots tab.
    Snapshot data --half

  2. To expand the snapshot data view, click the > icon, next to Variables and Call Stack.

  3. 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 it moves to that snapshot.
  4. 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.
    Snapshot frame

View snapshot data in the Lightrun Management Portal

Administrators can view snapshots from the Lightrun Management Portal. For more information, see Snapshot Data.

View and edit a snapshot

After you have created a snapshot, you can view and edit its configuration.

  1. In the Lightrun plugin, depending on the target, select either the Agents or Tags tab.
  2. Next to the Snapshot entry, click the Snapshot Options menu icon (...) and select Details.
    The Snapshot details window opens.
    Snapshot details
  3. To edit the configuration, click the edit icon Edit icon.
    The Edit a Snapshot dialog opens.
  4. In the respective fields, enter new values for line number, condition, hit limit, and so on.

Duplicate a snapshot action

  1. Hover your cursor over the relevant snapshot in the Lightrun sidebar.
  2. Right-click and select Duplicate.

    Duplicate snapshot --half

    The Insert a Snapshot dialog opens, displaying the data of the duplicated snapshot.

  3. Update any necessary details, such as modifying the code line or adjusting settings.

  4. Click Create to save the duplicated snapshot.

Export Snapshot data

Once a snapshot hit has been captured, it is possible to export the snapshot data for analysis in another IDE. Lightrun allows you to export the data of all available snapshots in your system, or the data of a single snapshot at once.

To export your entire Snapshot data
  1. Select the Snapshot tab in your Visual Studio Lightrun plugin.
  2. Click the Overflow menu icon (...) next to the search field and the SORT BY dropdown. Snapshot details -half
  3. Click Export all in the menu that appears. Pick your preferred storage location and click select to export the snapshots.
  4. A .lrsnapshot file will be saved in the selected location.
To export a single Snapshot data
  1. Select the Snapshot tab in your Visual Studio Lightrun plugin.
  2. Next to the Snapshot entry, click the Snapshot Options menu icon (...) and select Export. Pick your preferred storage location and click select to export the snapshot data.
  3. A .lrsnapshot file will be saved in the selected location.
To load a Snapshot file in your Visual Studio IDE
  1. Select the Snapshot tab in your Visual Studio Lightrun plugin.
  2. Click the Overflow menu icon (...) next to the search field and the SORT BY dropdown. Snapshot details -half
  3. Click Load Snapshots. Navigate to the snapshot file location and select the .lrsnapshot file to load the snapshot details in your IDE.

Last update: December 18, 2024