Module: Datadog::AppSec::Monitor::Gateway::Watcher

Defined in:
lib/datadog/appsec/monitor/gateway/watcher.rb

Overview

Watcher for Apssec internal events

Class Method Summary collapse

Class Method Details

.watchObject



15
16
17
18
19
# File 'lib/datadog/appsec/monitor/gateway/watcher.rb', line 15

def watch
  gateway = Instrumentation.gateway

  watch_user_id(gateway)
end

.watch_user_id(gateway = Instrumentation.gateway) ⇒ Object



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/datadog/appsec/monitor/gateway/watcher.rb', line 21

def watch_user_id(gateway = Instrumentation.gateway)
  gateway.watch('identity.set_user', :appsec) do |stack, user|
    block = false
    event = nil
    waf_context = Datadog::AppSec::Processor.active_context

    AppSec::Reactive::Operation.new('identity.set_user') do |op|
      trace = active_trace
      span = active_span

      Monitor::Reactive::SetUser.subscribe(op, waf_context) do |result, _block|
        if result.status == :match
          # TODO: should this hash be an Event instance instead?
          event = {
            waf_result: result,
            trace: trace,
            span: span,
            user: user,
            actions: result.actions
          }

          span.set_tag('appsec.event', 'true') if span

          waf_context.events << event
        end
      end

      _result, block = Monitor::Reactive::SetUser.publish(op, user)
    end

    throw(Datadog::AppSec::Ext::INTERRUPT, [nil, [:block, event]]) if block

    ret, res = stack.call(user)

    if event
      res ||= []
      res << [:monitor, event]
    end

    [ret, res]
  end
end