@@ -139,14 +139,40 @@ filter {
139139 if([transactionSummary] and [transactionSummary][protocol] in ["http", "https"]) {
140140 # Check, if an apiName is given (not the case for native APIs such as /healthcheck) to be used for the lookup
141141 if([transactionSummary][serviceContext][service]) {
142- mutate { add_field => { "[@metadata][apiName]" => "%{[transactionSummary][serviceContext][service]}" } }
142+ mutate {
143+ add_field => { "[@metadata][apiName]" => "%{[transactionSummary][serviceContext][service]}" }
144+ add_field => { "[@metadata][cacheAPIPaths]" => "${CACHE_API_PATHS:''}" }
145+ }
143146 } else {
144147 # Without an API name, only API path is used for the API lookup.
145148 mutate { add_field => { "[@metadata][apiName]" => "" } }
146149 }
147- # Create a key for the API
150+ # Create a cache key for the API either based on the received request path or the configured path.
151+ # For example: /v1/get/pet/687687678 --> CACHE_API_PER_NAME = /v1/get/pet makes sure the API is cached based on the API-Name
152+ ruby {
153+ code => '
154+ cacheAPIPaths = event.get("[@metadata][cacheAPIPaths]");
155+ apiRequestPath = event.get("[transactionSummary][path]");
156+ if (cacheAPIPaths.nil? || cacheAPIPaths.empty?)
157+ event.set("[@metadata][apiCacheKeyPrefix]", apiRequestPath);
158+ return;
159+ end
160+ apiName = event.get("[transactionSummary][serviceContext][service]");
161+ logger.info("Configured paths and current API-Request path: ", { "cacheAPIPaths" => cacheAPIPaths, "apiRequestPath" => apiRequestPath } );
162+ event.set("[@metadata][apiCacheKeyPrefix]", apiRequestPath);
163+ for configuredPath in cacheAPIPaths.split(",") do
164+ if(apiRequestPath.start_with?(configuredPath) )
165+ logger.info("Using configured path as primary cache key as it matches to request path. ", { "configuredPath" => configuredPath, "apiRequestPath" => apiRequestPath });
166+ event.set("[@metadata][apiCacheKeyPrefix]", configuredPath);
167+ break;
168+ end
169+ end
170+ '
171+ }
148172 mutate {
149- add_field => { "apiCacheKey" => "%{[transactionSummary][path]}###%{[processInfo][groupId]}###%{[processInfo][gatewayRegion]}" }
173+ add_field => {
174+ apiCacheKey => "%{[@metadata][apiCacheKeyPrefix]}###%{[processInfo][groupId]}###%{[processInfo][gatewayRegion]}"
175+ }
150176 }
151177 # Lookup the cache with the created API-Key (API-Name---API-Path)
152178 memcached {
0 commit comments