Module: Datadog::AppSec::Contrib::Devise::Patcher::RegistrationControllerPatch

Defined in:
lib/datadog/appsec/contrib/devise/patcher/registration_controller_patch.rb

Overview

Hook in devise registration controller

Instance Method Summary collapse

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/datadog/appsec/contrib/devise/patcher/registration_controller_patch.rb', line 14

def create
  return super unless AppSec.enabled?

  track_user_events_configuration = Datadog.configuration.appsec.track_user_events

  return super unless track_user_events_configuration.enabled

  automated_track_user_events_mode = track_user_events_configuration.mode

  appsec_scope = Datadog::AppSec.active_scope
  return super unless appsec_scope

  super do |resource|
    if resource.persisted?
      devise_resource = Resource.new(resource)

      event_information = Event.new(devise_resource, automated_track_user_events_mode)

      if event_information.user_id
        Datadog.logger.debug { 'User Signup Event' }
      else
        Datadog.logger.warn { 'User Signup Event, but can\'t extract user ID. Tracking empty event' }
      end

      Tracking.(
        appsec_scope.trace,
        appsec_scope.service_entry_span,
        user_id: event_information.user_id,
        **event_information.to_h
      )
    end

    yield resource if block_given?
  end
end