cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Null result for capture group on request naming regex

gmichels
Guide

Hello all,

 

I am trying to generalize the requests one app receives by leveraging request naming rules using regular expressions. Here are some requests to use as sample:

 

  • /v3/profiles/users/6941094/offices/3619
  • /v3/profiles/users/24325/offices/1123
  • /v3/profiles/users/41241/offices/65689/preferences
  • /v3/profiles/users/9893810/offices/83721
  • /v3/profiles/users/88720/offices/73334/roles

 

My goal is to have them all show in Dynatrace as :

 

  • /v3/profiles/users/<userid>/offices/<officeid>
  • /v3/profiles/users/<userid>/offices/<officeid>/roles
  • /v3/profiles/users/<userid>/offices/<officeid>/preferences

 

I am trying to tackle this using a single global request naming rule using placeholders (using global here because I need to have this done across multiple tenants):

 

 

{
    "enabled": true,
    "namingPattern": "{before_userid}/<userid>/offices/<officeid>{after_officeid}",
    "managementZones": [],
    "conditions": [
        {
            "attribute": "WEBREQUEST_URL_PATH",
            "comparisonInfo": {
                "type": "STRING",
                "comparison": "REGEX_MATCHES",
                "value": "[\\w\/]{1,100}\/users\/[\\w\/]{1,100}\/offices\/",
                "values": null,
                "negate": false,
                "caseSensitive": false
            }
        }
    ],
    "placeholders": [
        {
            "name": "before_userid",
            "attribute": "WEBREQUEST_URL_PATH",
            "kind": "REGEX_EXTRACTION",
            "delimiterOrRegex": "([\\w\/]{1,100}\/users)\/",
            "endDelimiter": null,
            "requestAttribute": null,
            "normalization": "TO_LOWER_CASE",
            "useFromChildCalls": null,
            "aggregation": null,
            "source": null
        },
        {
            "name": "after_officeid",
            "attribute": "WEBREQUEST_URL_PATH",
            "kind": "REGEX_EXTRACTION",
            "delimiterOrRegex": "\/offices\/\\d{1,10}([^$]*+)",
            "endDelimiter": null,
            "requestAttribute": null,
            "normalization": "TO_LOWER_CASE",
            "useFromChildCalls": null,
            "aggregation": null,
            "source": null
        }
    ]
}

 

 

The request naming rule I am using works perfectly for the samples that have something after the office id above, but it does not work for when the request simply ends in the office id number. I get this:

 

  • /v3/profiles/users/<userid>/offices/<officeid>/offices/3619
  • /v3/profiles/users/<userid>/offices/<officeid>/offices/1123
  • /v3/profiles/users/<userid>/offices/<officeid>/preferences
  • /v3/profiles/users/<userid>/offices/<officeid>/offices/83721
  • /v3/profiles/users/<userid>/offices/<officeid>/roles

 

For the requests that end up in simply the office id, the regex results for after_officeid end up in a null capture group:

 

gmichels_0-1662732827339.png

 

I would assume Dynatrace would use the null result from the capture group as a an empty string placeholder, but I am probably doing it wrong, as it's using the regex result itself in the replacement.

 

Does anyone have any clues on having the null result become an empty string, so the replacement works as expected? Apart from creating multiple rules, that is 🙂

 

Thanks

1 REPLY 1

Julius_Loman
DynaMight Guru
DynaMight Guru

@gmichels please have a look at this TIP POST which contains the solution for your case.

Certified Dynatrace Master | Alanata a.s., Slovakia, Dynatrace Master Partner