Skip to content

Metrics

You can add the following metrics to be tracked per line in your code:

Once you've added the metrics, view the outuput directly from the IDE.

Prerequisites

To use the plugin, make sure you have:

  • Attached at least one agent to your app
  • Installed the plugin in your local IntelliJ instance
  • Authenticated IntelliJ with your Lightrun account
  • Access to the server where the application with the agent is running
  • Opened the source code file for the running application from the IDE

Counters and time measures

Use counters and time metrics to help you measure how your code is running.

Once the action is added, the resulting output appears (based on piping configuration) from the:

  • IDE of the user who inserted it
  • IDE of any other user in the account
  • app in the browser for all users in the account
  • integrated APM and logging tools
  • terminal window on the application server from which the agent is running

Additionally, any user can use the action ID to view output from their CLI.

The counter action counts every time the given line was reached, periodically logging that information to the standard logger.

Similarly, you can add a time metric to measure the amount of time the specified code block runs, and then use this data to help investigate issues, track performance trouble or compare to other lines of code.

To add a counter
  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. Hover over Metrics and then click Counter or Time Measure (tictoc) from its sub-menu.

    The Create Counter appears as follows:

    Adding a Counter -third

    The Create Time Duration (tictoc) appears as follows:

    Adding a Counter -third

  4. Complete the fields in the dialog as follows:

    • Agent

      From the available options in this dropdown list, bind the action to a specific agent or tag.

    • File

      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.

    • Name

      a unique name used to distinguish between this and other counters in the printouts

    • Condition

      The condition of an if statement used to limit the execution of the action.

      !!! example

        The condition `myVar % 7 == 0` limits the log output so that it only prints for variables that are divisible by 7
      
  5. Click Advanced to configure the following additional fields:

    • Aggregate By (Counters only) - collect and aggregate data only for the referenced string
    • Ignore quotas

      The quota (rate limit) is configured in the agent configuration file. Ignore Quotas defaults to off. Only users assigned the IGNORE-QUOTA role can change this configuration; the checkbox is disabled for other users.

    • Expiry

      The time after which the action ceases to track code behavior and is automatically disabled; defaults to 1 hour.

  6. Click OK to add the metric. A marker is also added to the margins of the code on the line where it was inserted.

  7. Click Counter edit -icon to delete or edit the counter configuration. Click Time edit -icon to delete or edit the time measure metric configuration.

Measure duration

Measure the length of time taken for a specified block of code to run.

  1. Go to the line of your source code for which you'd like to measure duration.

  2. Right-click to open the context menu:

    Context Menu -half

  3. Hover over Metrics and then click Method Duration.

    The Create Measure Duration dialog opens:

    Create Method Duration -third

  4. Complete the fields in the dialog as follows:

    • Agent

      From the available options in this dropdown list, bind the action to a specific agent or tag.

    • Method -
    • Name

      a unique name used to distinguish between this and other counters in the printouts

    • Condition

      The condition of an if statement used to limit the execution of the action.

      !!! example

        The condition `myVar % 7 == 0` limits the log output so that it only prints for variables that are divisible by 7
      
  5. Click Advanced to configure the following additional fields:

    • Ignore quotas

      The quota (rate limit) is configured in the agent configuration file. Ignore Quotas defaults to off. Only users assigned the IGNORE-QUOTA role can change this configuration; the checkbox is disabled for other users.

    • Expiry

      The time after which the action ceases to track code behavior and is automatically disabled; defaults to 1 hour.

  6. Click OK to add the metric. An icon is added to the margins of the code on the line where it was added.

  7. Click Duration edit -icon from the log marker to delete or edit the log configuration.

Custom metrics

You can insert your own customized metrics using regular expressions.

To insert a custom metric
  1. Go to the line of your source code at which you'd like to insert custom metrics.

  2. Right-click to open the context menu:

    Context Menu -half

  3. Hover over Metrics and then click Custom Metric.

    The Create Custom Metric dialog opens:

    Create Custom Metric -third

  4. Complete the fields in the dialog as follows:

    • Agent

      From the available options in this dropdown list, bind the action to a specific agent or tag.

    • File

      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.

    • Name

      a unique name used to distinguish between this and other counters in the printouts

    • Expression

      variables or method results to be displayed in the stack trace of the snapshot; click + to enter additional expressions

    • Condition

      The condition of an if statement used to limit the execution of the action.

      !!! example

        The condition `myVar % 7 == 0` limits the log output so that it only prints for variables that are divisible by 7
      
  5. Click Advanced to configure the following additional fields:

    • Ignore quotas

      The quota (rate limit) is configured in the agent configuration file. Ignore Quotas defaults to off. Only users assigned the IGNORE-QUOTA role can change this configuration; the checkbox is disabled for other users.

    • Expiry

      The time after which the action ceases to track code behavior and is automatically disabled; defaults to 1 hour.

  6. Click OK to add the log. An icon is added to the margins of the code on the line where it was added.

  7. Click Custom edit -icon to delete or edit the counter configuration.

Update, edit, and delete actions

Once you've added an action, you can manipulate it by:

  • Viewing its details
  • Editing its configuration
  • Removing it
To work with existing actions

Once you create a snapshot or a metric, the relevant icon appears in the gutter of your code. When you enter a log, it is represented in line with your code. Icons for all of these options appear similar to those in the figure below.

Plugin gutter -quarter

  1. Hover over the relevant icon to view summary information from its tooltip.

  2. Click the log icon or right-click any icon in the gutter to edit, delete, and view details.

    Edit actions -quarter

View metric output

Data output is sent to your IDE, the CLI, the Lightrun Management Portal, or your integrated logging tools, depending on how you've configured piping.

By default, all output is piped to the Lightrun Management Portal. To view data from the IDE, you must configure the piping accordingly.

There are three levels of log piping:

  • App - the dynamic logs appear only in the Lightrun Management Portal, as they do by default.
  • Plugin - that dynamic logs won't appear in the Management Portal. Instead they appear in the Lightrun Console of your IDE, the CLI, or your integrated logging tools.
  • Both - that dynamic logs will appear both in the Management Portal and in any integrations you're using.

To configure piping:

  1. In the Lightrun plugin, navigate to the right-hand sidebar:

    Sidebar -quarter

  2. From the relevant agent, click Sidebar -icon to open the Piping menu:

    Log Piping -ten

  3. To view dynamic logs from the IDE, set either the Plugin or the Both option.

Note

Dynamic logs are sent from the agent to the plugin via the Lightrun management server. As this process is batched, dynamic logs may appear with a slight delay.

Lightrun dynamic logs and metrics normally are printed into the standard logging framework. This is quite valuable, as dynamic logs can be seen in the context of pre-existing log statements, which might provide further clues towards solving issues.

At the same time, you can see the log data output and, from your IDE, search and filter directly as you work. To do this, first configure log piping per agent. Once configured, all relevant information from any Lightrun actions that are added to the agents appears in the your console.

To view log data from IntelliJ

Once you've configured piping for the plugin and added at least one action to the code, dynamic logs and metrics begin updating in real time within the Lightrun Console, in the lower sidebar of IntelliJ:

Lightrun Console

  1. Use the filters at the top right of the Lightrun Console to filter the dynamic logs relevant to your investigation.

  2. Use the search bar at the top left to start typing and search dynamically for dynamic logs by name.

  3. To free memory or remove items already viewed, click Clear.


Last update: November 24, 2021