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

PRO TIP - Global request naming for REST services

Julius_Loman
DynaMight Guru
DynaMight Guru

Dynatrace does a pretty good job at request naming for common frameworks. Unfortunately, for some generic REST services, it may require request naming rules or URL cleanup rules, so requests are properly identified.

For example if your requests have names in Dynatrace such as:

  • /api/v1/client/123/data
  • /customers/812345/shopping-cart

instead of

  • /api/v1/client/[ID]/data
  • /customers/[ID]/shopping-cart

then you probably know you need to use the request naming rules. The request naming rules can be defined at a particular service. However, if you have many different request URL patterns, it's not efficient to define a rule for each one. There are even more challenges if you need to define such patterns on many services across multiple Dynatrace environments.

In such cases, it's worth considering Request naming rules API and defining a pattern to remove the numbers in requests names.

For the example from above to remove a number from an URL, we need to extract the prefix and postfix. Let's use regular expressions for that:

Prefix extraction pattern
^[a-z,/,\-,\d]*(?=/\d{1,})
Postfix extraction pattern
/\d{1,}(/.*+)
Condition pattern/\d{1,}


So our rule will be applied only if the Request URL matches the condition - a forward slash followed by a sequence of numbers. Additionally, we want to define a scope for this rule to apply. This can be accomplished for example by using tags or management zones in the conditions as well as other conditions.


In our case, the request naming rule payload for the API will look like the example below and it will be applied to a set of services tagged by the tag "REST Cleanup". Since this is a JSON payload, the regex patterns must be correctly escaped:

 

 

{
 "conditions": [
  {
   "attribute": "WEBREQUEST_URL_PATH",
   "comparisonInfo": {
    "caseSensitive": false,
    "comparison": "REGEX_MATCHES",
    "negate": false,
    "type": "STRING",
    "value": "/\\d{1,}",
    "values": null
   }
  },
  {
   "attribute": "SERVICE_TAG",
   "comparisonInfo": {
    "comparison": "TAG_KEY_EQUALS",
    "negate": false,
    "type": "TAG",
    "value": {
     "context": "CONTEXTLESS",
     "key": "REST Cleanup"
    },
    "values": null
   }
  }
 ],
 "enabled": true,
 "managementZones": [],
 "metadata": {
  "clusterVersion": "1.220.96.20210701-171424",
  "configurationVersions": [
   0
  ]
 },
 "namingPattern": "{prefix}/[ID]{postfix}",
 "placeholders": [
  {
   "aggregation": null,
   "attribute": "WEBREQUEST_URL_PATH",   
   "delimiterOrRegex": "^[a-z,/,\\-,\\d]*(?=/\\d{1,})",
   "endDelimiter": null,
   "kind": "REGEX_EXTRACTION",
   "name": "prefix",
   "normalization": "ORIGINAL",
   "requestAttribute": null,
   "source": null,
   "useFromChildCalls": false
  },
  {
   "aggregation": null,
   "attribute": "WEBREQUEST_URL_PATH",
   "delimiterOrRegex": "/\\d{1,}(/.*+)",
   "endDelimiter": null,
   "kind": "REGEX_EXTRACTION",
   "name": "postfix",
   "normalization": "ORIGINAL",
   "requestAttribute": null,
   "source": null,
   "useFromChildCalls": false
  }
 ]
}

 

 

 


After this rule is applied using the Request naming rules API you can see it also on your service in the Request naming settings section :

Julius_Loman_0-1637687498721.png
Now any future request for this service will have the desired naming with numbers removed.

TEMPEST a.s., Slovakia, Dynatrace Master Partner
0 REPLIES 0