Capture request attributes based on method arguments

Dynatrace allows you to create request attributes based on method arguments. To create a request attribute based on a method argument:

Go to Settings > Server-side monitoring > Request attributes.

Click the Create new request attribute button.

Provide a unique Request attribute name. You can rename an attribute at any point in the future.

Click the Add new data source button.

Optionally, define the scope of the request attribute.

From the Request attribute source drop list, select Java method parameter(s).

Click the Select method sources button to open the class wizard. Here you can select the class of the method upon whose argument you want to set an attribute.

Select the process group that contains the classes or interfaces you’re interested in and click Continue.

Search for the class that includes the method you’re interested in. Begin typing the class name and click the Search button. The list may take a few seconds to populate.

Pick a class from the displayed list. If the list doesn’t contain the class you’re looking for, refine the search string.

request attributes Java

Finally, pick one or more methods that you want to capture parameters from and click Finish.

The methods you selected are listed in the method argument capture rule (see below). For each method, from the list box under Capture, select the argument or return value of the method you want to capture.

request attributes Java

Notes

  • In addition to arguments and return values of any method, you can also capture the number of occurrences. While arguments and return values should be clear, occurrences can be a bit tricky. You should only use a single method rule when capturing occurrences. Dynatrace will count the number of calls of this method within a single request.
  • You can capture non-primitive and non-string objects. This can, however, result in increased performance overhead. Some objects may inadvertently change their state based on the method called, so use this option with caution.

You can always extend the list or remove methods later. Once saved, restart the processes that this rule applies to.

What's next?

Once your services begin calling the respective methods, you should see the request attribute appear on the service’s overview page, on the Request attributes tab.

request attributes Java

You can now use your request attribute to filter your data. In the PurePath example below, note the new request attribute in the header and within the respective service call’s summary section.

request attributes Java

Finally, notice that the code-level tree view also contains these methods. This view will be used later to display the argument values in case the method is called multiple times with different values.

request attributes Java

Optional post processing

In many cases, a captured value will contain what it is you’re looking for. However, you may not want an entire value, or even every value. In such cases, expand the Optionally restrict or process the captured parameter(s) further option to enable post processing through the included optional fields. This option becomes visible once you choose a value from the drop lists at the bottom, for example if you choose a value from the Request attribute source drop list.

Once you expand this option, you will be presented with 5 steps of post processing. Note that each step is optional, which means that it can be skipped. Also, steps are executed in the order presented and therefore each is applied onto the values rendered from the previous step.

post processing options for defining request attribute rule

The first step enables you to simply extract something from the resulting string. Extraction can be performed either before, after, or between values. The extraction happens in your application and is based on string searches. For example, if your value is <value>value1</value>, you can use the following to extract value1.

request attributes

If the combination can’t be found in the captured value, then nothing will be captured. If the extraction is successful then only the extracted value will be captured.

In step 2, you can provide a text separator to split the captured value.

In step 4, you can select the option of pruning whitespaces.

Step 4 enables further filtering through the options provided in the drop list. You can define the captured values to be further filtered by considering a value for example only if it begins with a specific character.

For complex use cases, you can apply at step 5 a regular expression to the captured values.

Numerical values, aggregations, and deep object access

By defining request attributes for your service requests, you can enable advanced filtering of service requests across all Dynatrace analysis views. Once configured, request attributes help you to better understand the relationships between performance, errors, and application-specific metadata in your requests.

In many cases, you end up in a situation where you want to capture an argument of a method and the method is called multiple times. Sometimes you’re only interested in a specific value. In other cases, you may only want to count the executions or average the captured values. Within other values, the argument in question may be a complex object and you’re really only interested in one aspect of the object.

To tackle such situations, you can use the Data type and the Aggregation on request drop lists when you define or configure a request attribute.

Choose and aggregate

It’s important to note that aggregation is applied not only within a single data source (for example, a method rule) but also across multiple data sources. The order is defined by:

  • Order of the data source rules
  • Order of the method rules within a method data source
  • Order of the method executions in your application (when a method is executed multiple times)

For text attributes, you can choose between the following options:

  • First occurrence
  • Last occurrence
  • Set of distinct values

The Set of distinct values option enables you to use all distinct values found in a request for filtering. For example, say a request captures a request attribute called Product and two values are captured for this attribute, Book and Video. You can filter by either of these values to find the request in question.

For integer or floating point values, you can additionally use the following aggregations:

  • Minimum of captured values
  • Maximum of captured values
  • Average of captured values
  • Sum of captured values

This makes a lot of sense when a value in question is numerical, for example, a metric or revenue.

The last two options are:

  • Count occurrences
  • Count distinct

If you choose one of these options, the data type changes to integer automatically. These settings are useful when you’re counting something.

Filtering numeric values

When you have an attribute that represents a number, you need to consider multiple filtering options. Attributes that have the data type Integer or Double can be filtered in multiple ways (see below).

request attributes

The two fields are both optional. If neither field is specified, Dynatrace checks for the existence of the attribute. If you specify both fields, the filter returns only those requests that have the specific attribute within the defined value range.

request attributes

Deep object access

A value that you’re interested in may not be available as a simple argument, but rather as part of a complex argument object or even a member variable of a class you’re looking at. Such values can still be easily accessed. As shown in the example below, you can access not only argument values and return values, but also objects itself. Whenever an item to be captured (be it an argument or an object) is a complex object, you have the ability to define a method (chain) that enables deep access into the object. The example below uses the method getBookingCode. You can even execute a chain, for example, getBookingCode().getCustomerCode().

request attributes

Note: The deep object access feature introduces new code into your application that must be executed. As such, it may change the state of your application or introduce performance impact. So, use this feature with caution.