Module: Datadog::AppSec::Contrib::Rails::Patches::RenderToBodyPatch

Defined in:
lib/datadog/appsec/contrib/rails/patches/render_to_body_patch.rb

Overview

A patch targeting ‘AbstractController::Rendering#render_to_body` method to capture JSON response body right before it is serialized.

Instance Method Summary collapse

Instance Method Details

#render_to_body(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/datadog/appsec/contrib/rails/patches/render_to_body_patch.rb', line 14

def render_to_body(options = {})
  return super unless options.key?(:json)

  context = request.env[Datadog::AppSec::Ext::CONTEXT_KEY]
  return super unless context

  data = Utils::HashCoercion.coerce(options[:json])
  return super unless data

  container = Instrumentation::Gateway::DataContainer.new(data, context: context)
  Instrumentation.gateway.push('rails.response.body.json', container)

  super
end