Dynatrace recently introduced the ability to capture Java method arguments and use them as request attributes. This valuable new service-monitoring feature enables fine-grain service filtering and performance analysis. By defining request attributes for your service’s 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.
We’ve now extended request attribute functionality to include .NET methods argument and return values.
Capture a .NET method argument value
To configure a request attribute
- Go to Settings > Server-side service monitoring > Request attributes.
- Click the Create new request attribute button.
- Click the Add new data source button.
- Optionally, define the scope of the request attribute (see complete instructions).
- From the Request attribute source drop list, select .NET method parameter(s).
- Click the Select method sources button to open the new .NET class wizard. Here you can select the .NET class of the method whose argument you want to set an attribute on.
- Begin by selecting the process group that contains the classes or interfaces you’re interested in and click Continue.
- Search for the .NET class that includes the method you’re interested in. Simply begin typing the .NET 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.
- Finally, pick one or more methods that you want to capture parameters from and click Finish.
The methods you select are listed in the method argument capture rule (see below). Now select which argument or return value you want to capture for each method.
You can always extend the list or remove methods later. Once saved, restart the processes that you want this rule to apply.
Once your services begin calling the respective methods, you should see the request attribute appear on the Request attributes tab of the service’s overview page (see example below).
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.
Finally, notice that the code-level tree view also contains these methods. This view tells you what the value was on each specific method—in case the method is called multiple times with different values.
Request attribute tips & tricks
In addition to argument values, you can also capture the Return value of any method, or simply the number of Occurrences. While 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.
Note: You can capture non-primitive and non-string objects. Read here how to access properties of complex objects. This can, however, result in increased performance overhead. Some objects may inadvertently change their state based on the method called, so be careful here.
Multiple possible values
It’s not hard to imagine that you may end up with multiple possible values. If this happens, simply define multiple data sources or multiple .NET methods. Even if you define a single .NET method, the method may be executed multiple times in a single request.
We’ve recently added a feature that deals with this. For details, see Request attributes: Numerical values, aggregations, & deep object access.
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, you can use the optional fields shown below to enable some post-processing.
Simple data extraction
The first part 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
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.
Only capture specific values
Following simple extraction, you can decide if you really want to capture the specific value. This happens after the pre-processing step mentioned above. This allows a simple string check that only captures values that fit a certain pattern.
Regex for advanced use cases
Finally, for really complex use cases, you can use a regular expression to extract something from the captured value. This happens following the two other pre-processing steps. You can use this regex in two different ways.
Lets say you have a value
Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0 Safari/537.36 and you want to capture the Windows version from this string. The regex
Windows NT[^)]+ will capture
Windows NT 10.0.
If you have more complicated needs you can use a group match. For example, if you want to extract the Chrome version without the word “Chrome,” use the regex
Chrome\/([^ )]+) to extract
56.0. In this case. only the group will be extracted and not the entire match.
Regular expressions are powerful, but they can lead to unexpected results (Lazy vs greedy matching) and they can quickly get expensive (Catastrophic Backtracking and repeated capture groups). For these reasons, we’ve decided to restrict regular expressions in Dynatrace:
- Quantified groups aren’t allowed. Please solve this in another way.
- Dynatrace doesn’t allow greedy matches within capture groups. Use lazy or possessive matching instead.
- Dynatrace allows exactly one capture group in places where you need to extract a value. The logic here is that if the regular expression contains a group, Dynatrace will use it. Otherwise, the full match is used for extraction.
- For pure matching cases, Dynatrace doesn’t allow any capture groups. Please use atomic groups instead.
- Dynatrace doesn’t allow back references.
This feature requires OneAgent version 129 or above.