Module: Datadog::Kit::AppSec::Events
- Defined in:
- lib/datadog/kit/appsec/events.rb
Overview
Tracking events
Constant Summary collapse
- LOGIN_SUCCESS_EVENT =
'users.login.success'
- LOGIN_FAILURE_EVENT =
'users.login.failure'
- SIGNUP_EVENT =
'users.signup'
- USER_LOGIN_KEYS =
['usr.login', :'usr.login'].freeze
Class Method Summary collapse
-
.track(event, trace = nil, span = nil, **others) ⇒ Object
Attach custom event information to the trace.
-
.track_login_failure(trace = nil, span = nil, user_exists:, user_id: nil, **others) ⇒ Object
Attach login failure event information to the trace.
-
.track_login_success(trace = nil, span = nil, user:, **others) ⇒ Object
Attach login success event information to the trace.
-
.track_signup(trace = nil, span = nil, user:, **others) ⇒ Object
Attach signup event information to the trace.
Class Method Details
.track(event, trace = nil, span = nil, **others) ⇒ Object
Attach custom event information to the trace
This method is experimental and may change in the future.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/datadog/kit/appsec/events.rb', line 116 def track(event, trace = nil, span = nil, **others) if trace && span check_trace_span_integrity(trace, span) span.set_tag("appsec.events.#{event}.track", 'true') span.set_tag("_dd.appsec.events.#{event}.sdk", 'true') others.each do |k, v| raise ArgumentError, 'key cannot be :track' if k.to_sym == :track span.set_tag("appsec.events.#{event}.#{k}", v) unless v.nil? end trace.keep! else set_trace_and_span_context('track', trace, span) do |active_trace, active_span| active_span.set_tag("appsec.events.#{event}.track", 'true') active_span.set_tag("_dd.appsec.events.#{event}.sdk", 'true') others.each do |k, v| raise ArgumentError, 'key cannot be :track' if k.to_sym == :track active_span.set_tag("appsec.events.#{event}.#{k}", v) unless v.nil? end active_trace.keep! end end ::Datadog::AppSec::Instrumentation.gateway.push('appsec.events.user_lifecycle', event) end |
.track_login_failure(trace = nil, span = nil, user_exists:, user_id: nil, **others) ⇒ Object
Attach login failure event information to the trace
This method is experimental and may change in the future.
61 62 63 64 65 66 67 68 69 |
# File 'lib/datadog/kit/appsec/events.rb', line 61 def track_login_failure(trace = nil, span = nil, user_exists:, user_id: nil, **others) set_trace_and_span_context('track_login_failure', trace, span) do |active_trace, active_span| others[:'usr.login'] = user_id if user_id && !others.key?(:'usr.login') && !others.key?('usr.login') track(LOGIN_FAILURE_EVENT, active_trace, active_span, **others) active_span.set_tag('appsec.events.users.login.failure.usr.id', user_id) if user_id active_span.set_tag('appsec.events.users.login.failure.usr.exists', user_exists) end end |
.track_login_success(trace = nil, span = nil, user:, **others) ⇒ Object
Attach login success event information to the trace
This method is experimental and may change in the future.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/datadog/kit/appsec/events.rb', line 30 def track_login_success(trace = nil, span = nil, user:, **others) set_trace_and_span_context('track_login_success', trace, span) do |active_trace, active_span| = user.dup user_id = .delete(:id) user_login = [:login] || others[:'usr.login'] || others['usr.login'] || user_id raise ArgumentError, 'missing required key: :user => { :id }' if user_id.nil? others = others.reject { |key, _| USER_LOGIN_KEYS.include?(key) } others[:'usr.login'] = user_login track(LOGIN_SUCCESS_EVENT, active_trace, active_span, **others) [:login] = user_login Kit::Identity.set_user(active_trace, active_span, id: user_id, **) end end |
.track_signup(trace = nil, span = nil, user:, **others) ⇒ Object
Attach signup event information to the trace
This method is experimental and may change in the future.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/datadog/kit/appsec/events.rb', line 85 def track_signup(trace = nil, span = nil, user:, **others) set_trace_and_span_context('track_signup', trace, span) do |active_trace, active_span| = user.dup user_id = .delete(:id) user_login = [:login] || others[:'usr.login'] || others['usr.login'] || user_id raise ArgumentError, 'missing required key: :user => { :id }' if user_id.nil? others = others.reject { |key, _| USER_LOGIN_KEYS.include?(key) } others[:'usr.login'] = user_login track(SIGNUP_EVENT, active_trace, active_span, **others) [:login] = user_login Kit::Identity.set_user(trace, id: user_id, **) end end |