File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed
lib/datadog/appsec/api_security
spec/datadog/appsec/api_security Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,9 @@ def self.route_pattern(request)
6464 # it does not have all the methods that ActionDispatch::Request has.
6565 # Before trying to use the router to recognize the route, we need to
6666 # create a new ActionDispatch::Request from the request env
67+ #
68+ # NOTE: Rails mutates HEAD request by changing the method to GET
69+ # and uses it for route recognition to check if the route is defined
6770 request = request . env [ RAILS_ROUTES_KEY ] . request_class . new ( request . env )
6871
6972 pattern = request . env [ RAILS_ROUTES_KEY ] . router
@@ -78,8 +81,8 @@ def self.route_pattern(request)
7881 else
7982 Tracing ::Contrib ::Rack ::RouteInference . read_or_infer ( request . env )
8083 end
81- rescue
82- AppSec . telemetry &.error ( 'AppSec: Could not extract route pattern for APISecurity sampler ' )
84+ rescue => e
85+ AppSec . telemetry &.report ( e , description : 'AppSec: Could not extract route pattern' )
8386
8487 nil
8588 end
Original file line number Diff line number Diff line change 219219 it { expect ( described_class . route_pattern ( request ) ) . to be_nil }
220220
221221 it 'reports the error via telemetry' do
222- expect ( telemetry ) . to receive ( :error ) . with ( 'AppSec: Could not extract route pattern for APISecurity sampler' )
222+ expect ( telemetry ) . to receive ( :report )
223+ . with ( an_instance_of ( StandardError ) , description : 'AppSec: Could not extract route pattern' )
223224
224225 described_class . route_pattern ( request )
225226 end
You can’t perform that action at this time.
0 commit comments