Skip to content

Work with Lightrun Snapshots in the JetBrains IDE

Overview

A snapshot is a one-time "breakpoint" that doesn't block your code from running. As opposed to a traditional breakpoint, snapshots collect the stack trace and variables without interrupting the application at all.

From your JetBrains IDE, you can:

Prerequisites

To use the plugin, make sure you have:

  1. Installed the plugin in your local IntelliJ instance.
  2. Authenticated IntelliJ with your Lightrun account.
  3. Attached at least one agent to your app.
  4. Opened the source code file for the running application from the IDE.

Add a snapshot

  1. Go to the line of your source code at which you'd like to insert the snapshot.

  2. Right-click to open the context menu:

    Context Menu -half

  3. Select Snapshot:

    The Create Snapshot dialog should appear similar to the following image.

    Adding a Snapshot -half

    The following table describes the present fields.

    Field Description
    Source From the available options in the dropdown list, bind the action to a specific agent, tag, or custom source.
    Click Create Custom Source to create a new custom source.
    Filename & Line The source code file and line of code into which you're inserting the snapshot. The default path is to the source code file from which you're currently working.
    Expression Variables or method results to be displayed in the snapshot stack trace. Click + to enter additional expressions.
    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.
    Max Hit Count the maximum number of times the snapshot should be taken during the lifetime of the action; default == 1.
  4. Click Advanced to configure the following additional fields:

    Field Description
    Ignore quotas The maximum number of times the snapshot should be taken during the lifetime of the action; default == 1.
    Expiry The time after which the action ceases to track code behavior and is automatically disabled; default = 1 hour.
  5. Click Save to add the snapshot.

    A snapshot marker Snapshot icon -icon should appear next to the selected code line in your Jetbrains code editor.

Once a snapshot hit has been captured, you will be notified directly in your IDE.

Snapshot icon -ten

View snapshot data

Once a snapshot hit has been captured, you can view the snapshot data directly in your IDE or in the Lightrun management portal in your browser. Click here for more information on how to view your snapshot data in the Lightrun management portal.

To view snapshot data in your IDE, click on the snapshot marker Snapshot icon -icon to open the Lightrun Snapshot window or click on Lightrun Snapshots in the bottom part of your IDE.

The Lightrun Snapshot tool window should appear similar to the following image.

Snapshot -half

Click on a snapshot to populate the Captured Hits, Frames, and Variables section with its data.

Snapshot -half

See JetBrains plugin quick tour to learn more about the Lightrun Snapshot tool window.

Edit and delete a snapshot

  1. Right-click on the snapshot marker Snapshot icon -icon on the snapshot code line.
  2. Click Delete to delete the snapshot.
  3. Click Edit to edit the snapshot configuration.

Copy and paste a Lightrun snapshot

This procedure allows you to easily reuse existing snapshots in multiple locations within your code. Note that the snapshot is saved in the clipboard and can be pasted multiple times.

  1. Right-click on the snapshot marker Snapshot icon -icon on the snapshot code line that you would like to copy.
  2. Click Copy to copy the snapshot settings.

    Snapshot copy -half

    The Insert a Counter window opens with the copied metrics.

  3. Update with a new counter name and click OK.

  4. Go to the line of your target source code at which you'd like to insert the copied snapshot, right-click and click Paste Snapshot.

    Snapshot paste -half

Debug Java lambda expressions in single-line code with Lightrun Snapshots

Note

Lightrun Lambda Snapshots are supported from version 1.48.1.

A single line of code may contain multiple points of interest for debugging, such as Lambda expressions in Java streams. Lightrun supports placing snapshots directly within Lambda expressions that are part of a single line of code (often referred to as "Java one-liners"). Typically, Lightrun snapshots are placed at the beginning of a line to capture the application's state before the line of code executes.

Capture the application's state during execution example

The following code example demonstrates the use of multiple Lambda expressions in a single line of code:

List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "David");

List<String> filteredNames = names.stream().filter(name -> name.startsWith("A")).map(name -> name.toUpperCase()).collect(Collectors.toList());
Using Lightrun's lambda Snapshots, you can place snapshots directly within the lambda expressions to capture the application's state during execution. For example:

  • In the .filter lambda: Capture the value of name to verify which names are being evaluated and filtered out.
  • In the .map lambda: Capture the transformed value of name to ensure the uppercase conversion is functioning as expected.

When adding a snapshot, Lightrun automatically detects lambda expressions on the selected line and offers options to place the snapshot either on the entire line or directly next to the detected lambda expressions. The dialog title confirms that a lambda snapshot has been selected. All operations—including adding, viewing, editing, and deleting—work the same for lambda snapshots as they do for line-based snapshots.

To add a lambda Snapshot

When working with lambda snapshots, the dialog titles indicate you are working on a Lambda snapshot. All operations—including adding, viewing, editing, and deleting—work the same for lambda snapshots as they do for line-based snapshots. For more information, refer to the relevant sections above.

  1. Navigate to the line of your source code containing the lambda expression where you'd like to insert the snapshot, and position the snapshot next to it.

  2. Right-click to open the context menu.

  3. Select Snapshot (Virtual Brakepoint).

    The line and the lambdas detected within it are listed.

  4. From the list, select a lambda expression.

    Select Lambda Snapshot --half

    The Insert a Lambda Snapshot dialog opens.

    Insert Lambda Snapshot --half

  5. In the Insert a Lambda Snapshot dialog, complete the fields (identical to line snapshots.

  6. Click Save.

    The lambda snapshot is added next to the selected code line and is added to the Actions tab, alongside line snapshots.

Lambda Snapshots in action

The following tutorial demonstrates how to add a lambda snapshot. For a line containing the lambda expression (e) -> (e.Ename.length() > 4 && e.City.length() > 4), the lambda expression is automatically detected.

Work with Lambda snapshots


Last update: February 20, 2025