09 Sep 2022 03:25 PM - last edited on 12 Sep 2022 09:40 AM by MaciejNeumann
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:
My goal is to have them all show in Dynatrace as :
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:
For the requests that end up in simply the office id, the regex results for after_officeid end up in a null capture group:
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
Solved! Go to Solution.
07 Oct 2022 07:25 PM - edited 07 Oct 2022 07:26 PM
Hi @Julius_Loman , thanks for the tip, it indeed helped me in some cases, but it still doesn't work appropriately when the URL ends solely in an ID. Using this request URL, for example :
The goal is to generalize both IDs, so it reads:
Using the regex suggested in the pro tip post, it does not match, as the regex requires something to exist after the 2nd ID:
/offices/\d++(/[^/]*+)$
Using an adaptation of the regex, so it matches, albeit the capture group output is now null:
/offices/\d{1,10}([^$]*+)
The end result in Dynatrace:
This is likely happening because when the capture group output is null, Dynatrace uses the match itself in the replacement. I would expect it to honor the null result and substitute the postfix replacement with an empty string.
Worth noting the rule works fine when there is something after the last number, such as:
Would you think of this as a bug? I can open a ticket with support and have them look at it.
Full request naming rule, for completeness (in Terraform notion, but it's pretty similar to the API request):
# for requests such as /v2/profiles/users/[ID]/offices/[ID]/roles
resource "dynatrace_request_naming" "_10_userid_officeid" {
enabled = true
naming_pattern = "{prefix}[ID]/offices/[ID]{postfix}"
conditions {
condition {
attribute = "WEBREQUEST_URL_PATH"
comparison {
negate = false
string {
case_sensitive = false
operator = "REGEX_MATCHES"
value = "/users/[\\w/]{1,100}/offices/"
}
}
}
}
placeholders {
placeholder {
name = "prefix"
attribute = "WEBREQUEST_URL_PATH"
delimiter_or_regex = "^(.*?/)\\d+"
kind = "REGEX_EXTRACTION"
normalization = "TO_LOWER_CASE"
}
placeholder {
name = "postfix"
attribute = "WEBREQUEST_URL_PATH"
delimiter_or_regex = "/offices/\\d{1,10}([^$]*+)"
kind = "REGEX_EXTRACTION"
normalization = "TO_LOWER_CASE"
}
}
}
Thank you,
Gustavo
07 Oct 2022 08:45 PM
Hey @gmichels ,
just tried that on your URL example (/v3/profiles/users/6941094/offices/3619
) and it works for me as expected with my generic rules:
Aren't some rules overriding the global ones in your case?
11 Oct 2022 07:22 PM
Hi @Julius_Loman, guess I was overthinking this and indeed it works as you highlighted, although it doesn't make much sense to me as the regex doesn't fully match. But I am going to stop complaining :).
The postfix rule needed amending, though, as it doesn't work when there are more sub-paths after the id. For example:
Was becoming simply:
Amended postfix regex with:
/\d++(/[^$]*+)$