@@ -222,6 +222,20 @@ function (SpanData $span, $args, $retval, $ex) use ($adapter, $service) {
222222 /*
223223 * Replicate CodeIgniter's route parsing, as matching key is never stored or returned in the framework.
224224 */
225+ private static function setNormalizedRoute ($ rootSpan , string $ pattern ): void {
226+ $ cacheKey = $ pattern ;
227+ $ normalizedRoute = \DDTrace \routing_cache_get ($ cacheKey );
228+ if ($ normalizedRoute === false ) {
229+ $ normalizedRoute = \DDTrace \Util \RouteNormalizer::normalizeFromCodeIgniter ($ pattern );
230+ if ($ normalizedRoute !== null ) {
231+ \DDTrace \routing_cache_set ($ cacheKey , $ normalizedRoute );
232+ }
233+ }
234+ if ($ normalizedRoute !== null && $ normalizedRoute !== false ) {
235+ $ rootSpan ->meta [Tag::APPSEC_NORMALIZED_ROUTE ] = $ normalizedRoute ;
236+ }
237+ }
238+
225239 private static function setHttpRoute ($ router , $ rootSpan ) {
226240 // Turn the segment array into a URI string
227241 $ uri = implode ('/ ' , $ router ->uri ->segments );
@@ -230,10 +244,7 @@ private static function setHttpRoute($router, $rootSpan) {
230244 if (isset ($ router ->routes [$ uri ]))
231245 {
232246 $ rootSpan ->meta [Tag::HTTP_ROUTE ] = $ uri ;
233- $ normalizedRoute = \DDTrace \Util \RouteNormalizer::normalizeFromCodeIgniter ($ uri );
234- if ($ normalizedRoute !== null ) {
235- $ rootSpan ->meta [Tag::APPSEC_NORMALIZED_ROUTE ] = $ normalizedRoute ;
236- }
247+ self ::setNormalizedRoute ($ rootSpan , $ uri );
237248 return ;
238249 }
239250
@@ -248,20 +259,14 @@ private static function setHttpRoute($router, $rootSpan) {
248259 if (preg_match ('#^ ' .$ key .'$# ' , $ uri ))
249260 {
250261 $ rootSpan ->meta [Tag::HTTP_ROUTE ] = $ origKey ;
251- $ normalizedRoute = \DDTrace \Util \RouteNormalizer::normalizeFromCodeIgniter ($ origKey );
252- if ($ normalizedRoute !== null ) {
253- $ rootSpan ->meta [Tag::APPSEC_NORMALIZED_ROUTE ] = $ normalizedRoute ;
254- }
262+ self ::setNormalizedRoute ($ rootSpan , $ origKey );
255263 return ;
256264 }
257265 }
258266
259267 // If we got this far it means we didn't encounter a
260268 // matching route so we'll set the site default route
261269 $ rootSpan ->meta [Tag::HTTP_ROUTE ] = $ uri ;
262- $ normalizedRoute = \DDTrace \Util \RouteNormalizer::normalizeFromCodeIgniter ($ uri );
263- if ($ normalizedRoute !== null ) {
264- $ rootSpan ->meta [Tag::APPSEC_NORMALIZED_ROUTE ] = $ normalizedRoute ;
265- }
270+ self ::setNormalizedRoute ($ rootSpan , $ uri );
266271 }
267272}
0 commit comments