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've attached at least one agent to your app.
  • You install the plugin in your local IntelliJ instance).
  • You authenticate IntelliJ with your Lightrun account.
  • Make sure you have access to the server where the application with the agent is running.
  • Be sure to open 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

      bind the action to a specific agent or tag from the available options in this dropdown list

    • File

      this is the source code file into which you're inserting the action; default is to the source code file from which you're already working

    • Name

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

    • Condition

      an expression that limits the action; this is the condition of an if statement used to limit the execution of the action

      !!! example myVar % 7 == 0 limits the log so 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 perform 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

      bind the action to a specific agent or tag from the available options in this dropdown list

    • Method -
    • Name

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

    • Condition

      an expression that limits the action; this is the condition of an if statement used to limit the execution of the action

      !!! example myVar % 7 == 0 limits the log so 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 perform 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

      bind the action to a specific agent or tag from the available options in this dropdown list

    • File

      this is the source code file into which you're inserting the action; default is to the source code file from which you're already 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

      an expression that limits the action; this is the condition of an if statement used to limit the execution of the action

      !!! example myVar % 7 == 0 limits the log so 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 perform 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 exising actions

Once you create snapshot or 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 the similar to the following:

Plugin gutter -quarter

  1. Hover over the relevant icon to read 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 Web Console, or your integrated logging tools depending on how you've configured piping.

By default, all output is piped to the Web Console in the Web Console. To view data from the IDE, you must first configure the piping accordingly.

There are three levels of log piping:

  • App - the dynamic logs appear only in the Lightrun Web Console, as they do by default.
  • Plugin - that dynamic logs won't appear in the Web Console. Instead they appear in the Lightrun Console of your IDE, the CLI, or your integrated logging tools.
  • Both - that dynamic logs wll appear both in the Web Console and in any integrations you're using.
To configure piping
  1. Navigate to the Lightrun right-hand sidebar:

    Sidebar -quarter

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

    Log Piping -ten

  3. Set the Plugin or the Both option to view dynamic logs from the IDE.

Note

In order to pipe the dynamic logs they need to go from the agent to the Management server and to the plugin. This process is batched so dynamic logs appear in batches and with some delay.

Lightrun dynamic logs and metrics are normally 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, a developer might want to see the log output and search and filter directly from the IDE as they 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 developers' consoles.

To view log data from IntelliJ

Once you configure piping for the plugin and add at least one action to the code, dynamic logs and metrics start updating in real time in the Lightrun Console at the bottom sidebar in IntelliJ:

Lightrun Console

  1. Use the filters at the top right of the Console data to filter for 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: August 2, 2021