Skip to content

Metrics

Overview

The Lightrun plugin for the IntelliJ IDEA provides four different metrics for monitoring the performance of your code and identifying issues:

  • Counters - Count the number of times a specific line of code is reached
  • Tic & Toc - Measure the elapsed time between two selected lines of code within a function
  • Method Duration - Measure the elapsed time for a method to execute
  • Custom Metrics - Create customized metrics, using parameters and simple or complex expressions that return a long int result

The following subsections describe, for each Lightrun metric, the procedures for:

Prerequisites

To use the plugin, make sure you have:

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

Support

Metrics are supported only for Java/JVM applications.

Adding metrics

Counters

A Lightrun Counter counts the number of times a specified line of code is reached and outputs the data periodically to the configured action target.

With a Lightrun Counter output, you can obtain a deeper insight into the state of your application's code, at any level of detail, from expressions and method calls to individual variables.

To insert a Counter into your code

  1. Place your cursor at the line in your source code where you want to insert the Counter, and Right-click to open the context menu
  2. Hover over Lightrun and, from the Metrics menu, select Counter. Context Menu -half The Create Counter dialog should appear similar to the following image.
    Adding a Counter -third
  3. Complete the fields in the dialog as follows:

    Fields Description
    SOURCE From the available options in the 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.
    Use the up/down arrows to change the line number for inserting the counter.
    NAME A meaningful label for the metric.
    TARGETS Select your preferred action output taget. 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.
    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.
  4. Click Advanced to configure the following additional fields:

    Fields Description
    AGGREGATED BY Group the metric based on thread names. Specify the required thread name prefix, followed by an asterisk.
    IGNORE QUOTA The quota (rate limit) is configured by the agent configurations.
    Only users with IGNORE_QUOTA role can override an agent's quota limitation, the IGNORE_QUOTA checkbox is disabled for other users.
    EXPIRY The time after which the action ceases to track code behavior and is automatically disabled; default = 1 hour.
  5. Click OK to add the Counter metric to your code. A Counter icon --icon icon should appear in the left gutter of the editor next to the code line where the action was added.

Time measures

There are two varieties of time measure metrics in Lightrun:

  • Method Duration - The Method Duration metric measures the elapsed time during the execution of a method (function), from the entry through a method call to the exit from the return expression.
  • Tic & Toc - The Tic & Toc metric measures the elapsed time of code execution between two specified lines, Tic (start line) and Toc (end line), in the same code block.

Note

The Tic (start line) and Toc (end line) both must be positioned inside the same code block.

To insert a Method Duration into your code

  1. Go to the line of your source code where the method is declared, and Right-click to open the context menu.
  2. Hover over Lightrun and, from the Metrics menu, click Method Duration. Context Menu -half The Create Measure Duration dialog should appear similar to the following image.
    Create Method Duration -third
  3. Complete the fields in the dialog as follows:

    Fields Description
    SOURCE From the available options in the 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.
    Use the up/down arrows to change the line number for inserting the counter.
    NAME A meaningful label for the metric.
    METHOD The name of the method (function) to which the Method Duration metric is to be applied.
    TARGETS Select your preferred action output taget. 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.
    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.
  4. Click Advanced, to configure the following additional fields:

    Fields Description
    IGNORE QUOTA The quota (rate limit) is configured by the agent configurations.
    Only users with IGNORE_QUOTA role can override an agent's quota limitation, the IGNORE_QUOTA checkbox is disabled for other users.
    EXPIRY The time after which the action ceases to track code behavior and is automatically disabled; default = 1 hour.
  5. Click OK to add the Method Duration metric to your code. A Duration edit --icon icon should appear in the left gutter of the editor, next to the code line where the action was added.

To insert a Tic & Toc into your code

  1. Place your cursor at the code line in the code block where you'd like to insert the Tic & Toc, and Right-click to open the context menu.
  2. Hover over Lightun and, from the Metrics menu, click Time measure (tictoc). Context Menu -half The Create Time Duration (tictoc) form should appear similar to the following image.
    Adding a Time Duration metric
  3. Complete the fields in the dialog as follows:

    Fields Description
    SOURCE From the available options in the 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.
    Use the up/down arrows to change the line number for inserting the counter.
    NAME A meaningful label for the metric.
    TARGETS Select your preferred action output taget. 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.
    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.
  4. Click Advanced, to configure the following additional fields:

    Fields Description
    IGNORE QUOTA The quota (rate limit) is configured by the agent configurations.
    Only users with IGNORE_QUOTA role can override an agent's quota limitation, the IGNORE_QUOTA checkbox is disabled for other users.
    EXPIRY The time after which the action ceases to track code behavior and is automatically disabled; default = 1 hour.
  5. Click OK to add the Tic & Toc metric to your code. A Tic & Toc --icon icon should appear in the left gutter of the editor, next to the code line where the action was added.

Custom Metrics

You can insert your own customized metrics expressions that evaluate to a long integer result.

To insert a Custom Metric into your code

  1. Place your cursor at the line in your source code where you want to insert the Custom Metric, and Right-click to open the context menu
  2. Hover over Lightrun and, from the Metrics menu, click Custom Metric. Context Menu -half The Create Custom Metric dialog should appear similar to the following image.
    Create Custom Metric -third
  3. Complete the fields in the dialog as follows:

    Fields Description
    SOURCE 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.
    Use the up/down arrows to change the line number for inserting the counter.
    NAME A meaningful label for the metric.
    TARGETS Select your preferred action output taget. 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.
    EXPRESSION Any expression - simple or complex - that evaluates to a numerical result.
    CONDITION The condition of an if statement, used to limit the execution of the action.
  4. Click Advanced, to configure the following additional fields:

    Fields Description
    IGNORE QUOTA The quota (rate limit) is configured by the agent configurations.
    Only users with IGNORE_QUOTA role can override an agent's quota limitation, the IGNORE_QUOTA checkbox is disabled for other users.
    EXPIRY The time after which the action ceases to track code behavior and is automatically disabled; default = 1 hour.
  5. Click OK to add the Custom Metric to your code. A Custom Metric icon Custom edit --icon should appear in the left gutter of the editor, next to the code line where the action was added.

Managing metrics

Once you've added a metric, you can:

  • Hover over a metrics icon in the editor gutter, to view summary information in a tooltip.
  • Right-click any icon in the gutter to delete or view details. Edit actions -half

Note

Because a metric's state is persistent during its lifetime (including between successive runs of the applications), they cannot be edited. A configuration modification requires the creation of a new metric.

Viewing metrics output

Lightrun dynamic logs and metrics, by default, are printed into the application’s standard output(Stdout). This process enables them to be analyzed in the context of pre-existing logs or metrics, which might provide further clues towards solving issues.

At the same time, you can also configure your action target to Plugin. This configuration lets you view your dynamic logs and metrics output directly in your IDE through the Lightrun Console, the Lightrun Management Portal, and third-party integrated apps like Slack or Prometheus.

Viewing logs and metrics from the IntelliJ Lightrun plugin

Once you've configured your action target to Plugin and added at least one dynamic log or metric to your code, the Lightrun Console should display real-time output from the added dynamic log or metric.

The Lightrun Console

You can control the display of logs in the IDE using any combination of the following options:

  • Use the filters at the top right of the Lightrun Console to filter the dynamic logs or metrics relevant to your investigation.
  • In the search bar at the top left, start typing to search dynamically for dynamic logs or metrics by name.
  • To free memory or remove items already viewed, click Clear.

Last update: September 20, 2022